<?php
/////////////////////////////////////////////////
// This function use for migrate raw data to temp data
/////////////////////////////////////////////////
function VoteDataCenter_remark_young(){
  pnShutDown();
}

function VoteDataCenter_remark_canvasser(){
  header ('Content-type: text/html; charset=utf-8');
  echo "Start migrate the province table.<br>";
    //Selection
    $query = "SELECT
                id1,
                mark_a1,
                mark_b1,
                id2,
                mark_a2,
                mark_b2,
                id3,
                mark_a3,
                mark_b3,
                id4,
                mark_a4,
                mark_b4,
                id5,
                mark_a5,
                mark_b5,
                id6,
                mark_a6,
                mark_b6,
                id7,
                mark_a7,
                mark_b7,
                id8,
                mark_a8,
                mark_b8,
                id9,
                mark_a9,
                mark_b9,
                id10,
                mark_a10,
                mark_b10,
                id11,
                mark_a11,
                mark_b11,
                id12,
                mark_a12,
                mark_b12,
                id13,
                mark_a13,
                mark_b13,
                id14,
                mark_a14,
                mark_b14,
                id15,
                mark_a15,
                mark_b15,
                id16,
                mark_a16,
                mark_b16,
                id17,
                mark_a17,
                mark_b17,
                id18,
                mark_a18,
                mark_b18,
                id19,
                mark_a19,
                mark_b19,
                id20,
                mark_a20,
                mark_b20,
                id21,
                mark_a21,
                mark_b21,
                id22,
                mark_a22,
                mark_b22,
                id23,
                mark_a23,
                mark_b23,
                id24,
                mark_a24,
                mark_b24
              FROM 
                remark.sungmen 
              ";
                //remark.ramark 
    $column = array(
                    "id1",
                    "mark_a1",
                    "mark_b1",
                    "id2",
                    "mark_a2",
                    "mark_b2",
                    "id3",
                    "mark_a3",
                    "mark_b3",
                    "id4",
                    "mark_a4",
                    "mark_b4",
                    "id5",
                    "mark_a5",
                    "mark_b5",
                    "id6",
                    "mark_a6",
                    "mark_b6",
                    "id7",
                    "mark_a7",
                    "mark_b7",
                    "id8",
                    "mark_a8",
                    "mark_b8",
                    "id9",
                    "mark_a9",
                    "mark_b9",
                    "id10",
                    "mark_a10",
                    "mark_b10",
                    "id11",
                    "mark_a11",
                    "mark_b11",
                    "id12",
                    "mark_a12",
                    "mark_b12",
                    "id13",
                    "mark_a13",
                    "mark_b13",
                    "id14",
                    "mark_a14",
                    "mark_b14",
                    "id15",
                    "mark_a15",
                    "mark_b15",
                    "id16",
                    "mark_a16",
                    "mark_b16",
                    "id17",
                    "mark_a17",
                    "mark_b17",
                    "id18",
                    "mark_a18",
                    "mark_b18",
                    "id19",
                    "mark_a19",
                    "mark_b19",
                    "id20",
                    "mark_a20",
                    "mark_b20",
                    "id21",
                    "mark_a21",
                    "mark_b21",
                    "id22",
                    "mark_a22",
                    "mark_b22",
                    "id23",
                    "mark_a23",
                    "mark_b23",
                    "id24",
                    "mark_a24",
                    "mark_b24"
              );
    $result = DBUtil::executeSQL($query);
    $remarkArray = DBUtil::marshallObjects ($result, $column);
    unset($result);

  $row = 1;
  foreach($remarkArray as $remark){

    for($i=1; $i<=24; $i++){
      //Update 1
      $idName = "id".$i;
      $ramark1Name = "mark_a".$i;
      $ramark2Name = "mark_b".$i;

      if($remark[$idName] != 0){
        $len = strlen($remark[$idName]); 
        $id =  substr($remark[$idName],0,($len-1));
        $where = "pn_degis_contact.aco_id = ".$id;
        $query = "UPDATE
                    zikuladb.pn_degis_contact
                  SET
                    pn_degis_contact.aco_remarkv = ".$remark[$ramark1Name].",
                    pn_degis_contact.aco_remarkv2 = ".$remark[$ramark2Name]."
                  WHERE ".
                    $where;
        //var_dump($query); exit;
        echo $i."<br>".$query."<br>";
        DBUtil::executeSQL($query);
      }
    }

    echo $row++."-----------------------------------<br>";
  }
    unset($remarkArray);
  pnShutDown();
}

function VoteDataCenter_remark_surat(){
  header ('Content-type: text/html; charset=utf-8');
  echo "Start migrate the remark table.<br>";
    //Selection
    $query = "SELECT
                id1,
                mark_a1,
                mark_b1,
                mark_c1,
                id2,
                mark_a2,
                mark_b2,
                mark_c2,
                id3,
                mark_a3,
                mark_b3,
                mark_c3,
                id4,
                mark_a4,
                mark_b4,
                mark_c4,
                id5,
                mark_a5,
                mark_b5,
                mark_c5,
                id6,
                mark_a6,
                mark_b6,
                mark_c6,
                id7,
                mark_a7,
                mark_b7,
                mark_c7,
                id8,
                mark_a8,
                mark_b8,
                mark_c8,
                id9,
                mark_a9,
                mark_b9,
                mark_c9,
                id10,
                mark_a10,
                mark_b10,
                mark_c10,
                id11,
                mark_a11,
                mark_b11,
                mark_c11,
                id12,
                mark_a12,
                mark_b12,
                mark_c12,
                id13,
                mark_a13,
                mark_b13,
                mark_c13,
                id14,
                mark_a14,
                mark_b14,
                mark_c14,
                id15,
                mark_a15,
                mark_b15,
                mark_c15,
                id16,
                mark_a16,
                mark_b16,
                mark_c16,
                id17,
                mark_a17,
                mark_b17,
                mark_c17,
                id18,
                mark_a18,
                mark_b18,
                mark_c18,
                id19,
                mark_a19,
                mark_b19,
                mark_c19,
                id20,
                mark_a20,
                mark_b20,
                mark_c20,
                id21,
                mark_a21,
                mark_b21,
                mark_c21,
                id22,
                mark_a22,
                mark_b22,
                mark_c22,
                id23,
                mark_a23,
                mark_b23,
                mark_c23,
                id24,
                mark_a24,
                mark_b24,
                mark_c24
              FROM 
                suratremark.suratmark 
              ";
                //remark.ramark 
    $column = array(
                    "id1",
                    "mark_a1",
                    "mark_b1",
                    "mark_c1",
                    "id2",
                    "mark_a2",
                    "mark_b2",
                    "mark_c2",
                    "id3",
                    "mark_a3",
                    "mark_b3",
                    "mark_c3",
                    "id4",
                    "mark_a4",
                    "mark_b4",
                    "mark_c4",
                    "id5",
                    "mark_a5",
                    "mark_b5",
                    "mark_c5",
                    "id6",
                    "mark_a6",
                    "mark_b6",
                    "mark_c6",
                    "id7",
                    "mark_a7",
                    "mark_b7",
                    "mark_c7",
                    "id8",
                    "mark_a8",
                    "mark_b8",
                    "mark_c8",
                    "id9",
                    "mark_a9",
                    "mark_b9",
                    "mark_c9",
                    "id10",
                    "mark_a10",
                    "mark_b10",
                    "mark_c10",
                    "id11",
                    "mark_a11",
                    "mark_b11",
                    "mark_c11",
                    "id12",
                    "mark_a12",
                    "mark_b12",
                    "mark_c12",
                    "id13",
                    "mark_a13",
                    "mark_b13",
                    "mark_c13",
                    "id14",
                    "mark_a14",
                    "mark_b14",
                    "mark_c14",
                    "id15",
                    "mark_a15",
                    "mark_b15",
                    "mark_c15",
                    "id16",
                    "mark_a16",
                    "mark_b16",
                    "mark_c16",
                    "id17",
                    "mark_a17",
                    "mark_b17",
                    "mark_c17",
                    "id18",
                    "mark_a18",
                    "mark_b18",
                    "mark_c18",
                    "id19",
                    "mark_a19",
                    "mark_b19",
                    "mark_c19",
                    "id20",
                    "mark_a20",
                    "mark_b20",
                    "mark_c20",
                    "id21",
                    "mark_a21",
                    "mark_b21",
                    "mark_c21",
                    "id22",
                    "mark_a22",
                    "mark_b22",
                    "mark_c22",
                    "id23",
                    "mark_a23",
                    "mark_b23",
                    "mark_c23",
                    "id24",
                    "mark_a24",
                    "mark_b24",
                    "mark_c24"
              );
    $result = DBUtil::executeSQL($query);
    $remarkArray = DBUtil::marshallObjects ($result, $column);
    unset($result);

  $row = 1;
  foreach($remarkArray as $remark){

    for($i=1; $i<=24; $i++){
      //Update 1
      $idName = "id".$i;
      $ramark1Name = "mark_a".$i;
      $ramark2Name = "mark_b".$i;
      $ramark3Name = "mark_c".$i;
      if($remark[$idName] != 0){

        if($remark[$ramark1Name] == 1){
          $len = strlen($remark[$idName]); 
          $id =  substr($remark[$idName],0,($len-1));
          $where = "pn_degis_contact.aco_id = ".$id;
          $query = "UPDATE
                      suratdemap.pn_degis_contact
                    SET
                      pn_degis_contact.aco_remarkv = ".$remark[$ramark1Name]."
                    WHERE ".
                      $where;
          //var_dump($query); exit;
          echo $i."<br>".$query."<br>";
          DBUtil::executeSQL($query);
        }

        if($remark[$ramark2Name] == 1){
          $len = strlen($remark[$idName]); 
          $id =  substr($remark[$idName],0,($len-1));
          $where = "pn_degis_contact.aco_id = ".$id;
          $query = "UPDATE
                      suratdemap.pn_degis_contact
                    SET
                      pn_degis_contact.aco_remarkv = ".$remark[$ramark2Name]."
                    WHERE ".
                      $where;
          //var_dump($query); exit;
          echo $i."<br>".$query."<br>";
          DBUtil::executeSQL($query);
        }

        if($remark[$ramark3Name] == 1){
          $len = strlen($remark[$idName]); 
          $id =  substr($remark[$idName],0,($len-1));
          $where = "pn_degis_contact.aco_id = ".$id;
          $query = "UPDATE
                      suratdemap.pn_degis_contact
                    SET
                      pn_degis_contact.aco_remarkv = ".$remark[$ramark3Name]."
                    WHERE ".
                      $where;
          //var_dump($query); exit;
          echo $i."<br>".$query."<br>";
          DBUtil::executeSQL($query);
        }
      }
    }

    echo $row++."-----------------------------------<br>";
  }
    unset($remarkArray);
  pnShutDown();
}


function VoteDataCenter_remark_report(){
  $form = FormUtil::getPassedValue ('form', null, 'REQUEST');
  //var_dump($form); exit;
//Select pamat
  $render = pnRender::getInstance('VoteDataCenter');
  if($form['vil_id']){

    //var_dump($form['vil_id']); exit;
    //Select all
    $query = "SELECT 	aco_addr_moo, COUNT(aco_id) as count_all
                      FROM 
                        zikuladb.pn_degis_contact 
                      WHERE aco_tumbol_id = ".$form['tam_id']."
                      AND aco_addr_moo = ".$form['vil_id']."
                      GROUP BY aco_addr_moo
                      ORDER BY CAST(aco_addr_moo AS SIGNED INTEGER)";
      //echo $query; 
      $column = array(
                "name", "count_all"
                );

      $result = DBUtil::executeSQL($query);
      $allMoooArray = DBUtil::marshallObjects ($result, $column);

    //Select we
    $query = "SELECT 	aco_addr_moo, COUNT(aco_id) AS count_we
                      FROM 
                        zikuladb.pn_degis_contact 
                      WHERE aco_tumbol_id = ".$form['tam_id']."
                      AND aco_addr_moo = ".$form['vil_id']."
                      AND aco_remarkv =1
                      GROUP BY aco_addr_moo
                      ORDER BY CAST(aco_addr_moo AS SIGNED INTEGER)";

      $column = array(
                "name", "count_we"
                );

      $result = DBUtil::executeSQL($query);
      $weMoooArray = DBUtil::marshallObjects ($result, $column);

    //Select they
    $query = "SELECT 	aco_addr_moo, COUNT(aco_id) AS count_they
                      FROM 
                        zikuladb.pn_degis_contact 
                      WHERE aco_tumbol_id = ".$form['tam_id']."
                      AND aco_addr_moo = ".$form['vil_id']."
                      AND aco_remarkv = 0
                      AND aco_remarkv2 =1
                      GROUP BY aco_addr_moo
                      ORDER BY CAST(aco_addr_moo AS SIGNED INTEGER)";

      $column = array(
                "name", "count_they"
                );

      $result = DBUtil::executeSQL($query);
      $theyMoooArray = DBUtil::marshallObjects ($result, $column);

    //Select unknown
    $query = "SELECT 	aco_addr_moo, COUNT(aco_id) AS count_unknown
                      FROM 
                        zikuladb.pn_degis_contact 
                      WHERE aco_tumbol_id = ".$form['tam_id']."
                      AND aco_addr_moo = ".$form['vil_id']."
                      AND aco_remarkv =0
                      AND aco_remarkv2 =0
                      GROUP BY aco_addr_moo
                      ORDER BY CAST(aco_addr_moo AS SIGNED INTEGER)";

      $column = array(
                "name", "count_unknown"
                );

      $result = DBUtil::executeSQL($query);
      $unknownMoooArray = DBUtil::marshallObjects ($result, $column);

      $reArray = array();
      
      $sum_count_all = 0;
      $sum_count_we = 0;
      $sum_count_they = 0;
      $sum_count_unknown = 0;
      $sum_count_none_canvasser = 0;

      for($i=0; $i<count($allMoooArray); $i++){
        $compare = false;
        $compareThey = false;
        $compareUnknown = false;
        //Comoare we
        for($j=0; $j<count($weMoooArray); $j++){
          if($weMoooArray[$j]['name'] == $allMoooArray[$i]['name']){
            //echo $weMoooArray[$j]['aco_addr_moo']." with ".$allMoooArray[$i]['aco_addr_moo']."<br>";
            $compare = true;
            $weValue = $weMoooArray[$j]['count_we'];
          }
        }

        //Comoare they
        for($k=0; $k<count($theyMoooArray); $k++){
          if($theyMoooArray[$k]['name'] == $allMoooArray[$i]['name']){
            //echo $theyMoooArray[$k]['aco_addr_moo']." with ".$allMoooArray[$i]['aco_addr_moo']."<br>";
            $compareThey = true;
            $theyValue = $theyMoooArray[$k]['count_they'];
          }
        }

        //Comoare unknow
        for($l=0; $l<count($unknownMoooArray); $l++){
          if($unknownMoooArray[$l]['name'] == $allMoooArray[$i]['name']){
            //echo $unknownMoooArray[$l]['aco_addr_moo']." with ".$allMoooArray[$i]['aco_addr_moo']."<br>";
            $compareUnknown = true;
            $unknownValue = $unknownMoooArray[$l]['count_unknown'];
          }
        }

        if($compare == true && $compareThey == true && $compareUnknown == true){
            $reArray[$i] = array('name' => $allMoooArray[$i]['name'],
                                    'count_all' => $allMoooArray[$i]['count_all'],
                                    'count_we' => $weValue,
                                    'count_they' => $theyValue,
                                    'count_unknown' => $unknownValue
                              );
          $sum_count_all += $allMoooArray[$i]['count_all'];
          $sum_count_we += $weValue;
          $sum_count_they += $theyValue;
          $sum_count_unknown += $unknownValue;
          $sum_all_count_unknown += $unknownValue;
        }else if($compare == false && $compareThey == true && $compareUnknown == true){
            $reArray[$i] = array('name' => $allMoooArray[$i]['name'],
                                    'count_all' => $allMoooArray[$i]['count_all'],
                                    'count_we' => "0",
                                    'count_they' => $theyValue,
                                    'count_unknown' => $unknownValue
                              );
          $sum_count_all += $allMoooArray[$i]['count_all'];
          $sum_count_they += $theyValue;
          $sum_count_unknown += $unknownValue;
          $sum_all_count_unknown += $unknownValue;
        }else if($compare == true && $compareThey == false && $compareUnknown == true){
            $reArray[$i] = array('name' => $allMoooArray[$i]['name'],
                                    'count_all' => $allMoooArray[$i]['count_all'],
                                    'count_we' => $weValue,
                                    'count_they' => "0",
                                    'count_unknown' => $unknownValue
                              );
          $sum_count_all += $allMoooArray[$i]['count_all'];
          $sum_count_we += $weValue;
          $sum_count_unknown += $unknownValue;
          $sum_all_count_unknown += $unknownValue;
        }else if($compare == true && $compareThey == true && $compareUnknown == false){
            $reArray[$i] = array('name' => $allMoooArray[$i]['name'],
                                    'count_all' => $allMoooArray[$i]['count_all'],
                                    'count_we' => $weValue,
                                    'count_they' => $theyValue,
                                    'count_unknown' => "0"
                              );
          $sum_count_all += $allMoooArray[$i]['count_all'];
          $sum_count_we += $weValue;
          $sum_count_they += $theyValue;
        }else if($compare == false && $compareThey == true && $compareUnknown == true){
            $reArray[$i] = array('name' => $allMoooArray[$i]['name'],
                                    'count_all' => $allMoooArray[$i]['count_all'],
                                    'count_we' => "0",
                                    'count_they' => $theyValue,
                                    'count_unknown' => $unknownValue
                              );
          $sum_count_all += $allMoooArray[$i]['count_all'];
          $sum_count_they += $theyValue;
          $sum_count_unknown += $unknownValue;
          $sum_all_count_unknown += $unknownValue;
        }else if($compare == true && $compareThey == false && $compareUnknown == false){
            $reArray[$i] = array('name' => $allMoooArray[$i]['name'],
                                    'count_all' => $allMoooArray[$i]['count_all'],
                                    'count_we' => $weValue,
                                    'count_they' => "0",
                                    'count_unknown' => "0"
                              );
          $sum_count_all += $allMoooArray[$i]['count_all'];
          $sum_count_we += $weValue;
        }else if($compare == false && $compareThey == true && $compareUnknown == false){
            $reArray[$i] = array('name' => $allMoooArray[$i]['name'],
                                    'count_all' => $allMoooArray[$i]['count_all'],
                                    'count_we' => "0",
                                    'count_they' => $theyValue,
                                    'count_unknown' =>  "0"
                              );
          $sum_count_all += $allMoooArray[$i]['count_all'];
          $sum_count_they += $theyValue;
        }else if($compare == false && $compareThey == false && $compareUnknown == true){
            $reArray[$i] = array('name' => $allMoooArray[$i]['name'],
                                    'count_all' => $allMoooArray[$i]['count_all'],
                                    'count_we' => "0",
                                    'count_they' => "0",
                                    'count_unknown' => $unknownValue
                              );
          $sum_count_all += $allMoooArray[$i]['count_all'];
          $sum_count_none_canvasser += $unknownValue;
          $sum_all_count_unknown += $unknownValue;
        }
    }
    //var_dump($reArray); exit;

    $render->assign('tam_id', $form['tam_id']);
    $render->assign('sum_count_all', $sum_count_all);
    $render->assign('sum_count_we', $sum_count_we);
    $render->assign('sum_count_they', $sum_count_they);
    $render->assign('sum_count_none_canvasser', $sum_count_none_canvasser);
    $render->assign('sum_all_count_unknown', $sum_all_count_unknown);
    $render->assign('sum_count_unknown', $sum_count_unknown);
    $render->assign('objectArray', $reArray);

  }else if($form['vil_id'] == 0 && $form['tam_id']){
    //Select all
    $query = "SELECT 	aco_addr_moo, COUNT(aco_id) as count_all
                      FROM 
                        zikuladb.pn_degis_contact 
                      WHERE aco_tumbol_id = ".$form['tam_id']."
                      GROUP BY aco_addr_moo
                      ORDER BY CAST(aco_addr_moo AS SIGNED INTEGER)";

      $column = array(
                "name", "count_all"
                );

      $result = DBUtil::executeSQL($query);
      $allMoooArray = DBUtil::marshallObjects ($result, $column);

    //Select we
    $query = "SELECT 	aco_addr_moo, COUNT(aco_id) AS count_we
                      FROM 
                        zikuladb.pn_degis_contact 
                      WHERE aco_tumbol_id = ".$form['tam_id']."
                      AND aco_remarkv =1
                      GROUP BY aco_addr_moo
                      ORDER BY CAST(aco_addr_moo AS SIGNED INTEGER)";

      $column = array(
                "name", "count_we"
                );

      $result = DBUtil::executeSQL($query);
      $weMoooArray = DBUtil::marshallObjects ($result, $column);

    //Select they
    $query = "SELECT 	aco_addr_moo, COUNT(aco_id) AS count_they
                      FROM 
                        zikuladb.pn_degis_contact 
                      WHERE aco_tumbol_id = ".$form['tam_id']."
                      AND aco_remarkv = 0
                      AND aco_remarkv2 =1
                      GROUP BY aco_addr_moo
                      ORDER BY CAST(aco_addr_moo AS SIGNED INTEGER)";

      $column = array(
                "name", "count_they"
                );

      $result = DBUtil::executeSQL($query);
      $theyMoooArray = DBUtil::marshallObjects ($result, $column);

    //Select unknown
    $query = "SELECT 	aco_addr_moo, COUNT(aco_id) AS count_unknown
                      FROM 
                        zikuladb.pn_degis_contact 
                      WHERE aco_tumbol_id = ".$form['tam_id']."
                      AND aco_remarkv =0
                      AND aco_remarkv2 =0
                      GROUP BY aco_addr_moo
                      ORDER BY CAST(aco_addr_moo AS SIGNED INTEGER)";

      $column = array(
                "name", "count_unknown"
                );

      $result = DBUtil::executeSQL($query);
      $unknownMoooArray = DBUtil::marshallObjects ($result, $column);

      $reArray = array();
      
      $sum_count_all = 0;
      $sum_count_we = 0;
      $sum_count_they = 0;
      $sum_count_unknown = 0;
      $sum_count_none_canvasser = 0;
      for($i=0; $i<count($allMoooArray); $i++){
        $compare = false;
        $compareThey = false;
        $compareUnknown = false;
        //Comoare we
        for($j=0; $j<count($weMoooArray); $j++){
          if($weMoooArray[$j]['name'] == $allMoooArray[$i]['name']){
            //echo $weMoooArray[$j]['aco_addr_moo']." with ".$allMoooArray[$i]['aco_addr_moo']."<br>";
            $compare = true;
            $weValue = $weMoooArray[$j]['count_we'];
          }
        }

        //Comoare they
        for($k=0; $k<count($theyMoooArray); $k++){
          if($theyMoooArray[$k]['name'] == $allMoooArray[$i]['name']){
            //echo $theyMoooArray[$k]['aco_addr_moo']." with ".$allMoooArray[$i]['aco_addr_moo']."<br>";
            $compareThey = true;
            $theyValue = $theyMoooArray[$k]['count_they'];
          }
        }

        //Comoare unknow
        for($l=0; $l<count($unknownMoooArray); $l++){
          if($unknownMoooArray[$l]['name'] == $allMoooArray[$i]['name']){
            //echo $unknownMoooArray[$l]['aco_addr_moo']." with ".$allMoooArray[$i]['aco_addr_moo']."<br>";
            $compareUnknown = true;
            $unknownValue = $unknownMoooArray[$l]['count_unknown'];
          }
        }

        if($compare == true && $compareThey == true && $compareUnknown == true){
            $reArray[$i] = array('name' => $allMoooArray[$i]['name'],
                                    'count_all' => $allMoooArray[$i]['count_all'],
                                    'count_we' => $weValue,
                                    'count_they' => $theyValue,
                                    'count_unknown' => $unknownValue
                              );
          $sum_count_all += $allMoooArray[$i]['count_all'];
          $sum_count_we += $weValue;
          $sum_count_they += $theyValue;
          $sum_count_unknown += $unknownValue;
          $sum_all_count_unknown += $unknownValue;
        }else if($compare == false && $compareThey == true && $compareUnknown == true){
            $reArray[$i] = array('name' => $allMoooArray[$i]['name'],
                                    'count_all' => $allMoooArray[$i]['count_all'],
                                    'count_we' => "0",
                                    'count_they' => $theyValue,
                                    'count_unknown' => $unknownValue
                              );
          $sum_count_all += $allMoooArray[$i]['count_all'];
          $sum_count_they += $theyValue;
          $sum_count_unknown += $unknownValue;
          $sum_all_count_unknown += $unknownValue;
        }else if($compare == true && $compareThey == false && $compareUnknown == true){
            $reArray[$i] = array('name' => $allMoooArray[$i]['name'],
                                    'count_all' => $allMoooArray[$i]['count_all'],
                                    'count_we' => $weValue,
                                    'count_they' => "0",
                                    'count_unknown' => $unknownValue
                              );
          $sum_count_all += $allMoooArray[$i]['count_all'];
          $sum_count_we += $weValue;
          $sum_count_unknown += $unknownValue;
          $sum_all_count_unknown += $unknownValue;
        }else if($compare == true && $compareThey == true && $compareUnknown == false){
            $reArray[$i] = array('name' => $allMoooArray[$i]['name'],
                                    'count_all' => $allMoooArray[$i]['count_all'],
                                    'count_we' => $weValue,
                                    'count_they' => $theyValue,
                                    'count_unknown' => "0"
                              );
          $sum_count_all += $allMoooArray[$i]['count_all'];
          $sum_count_we += $weValue;
          $sum_count_they += $theyValue;
        }else if($compare == false && $compareThey == true && $compareUnknown == true){
            $reArray[$i] = array('name' => $allMoooArray[$i]['name'],
                                    'count_all' => $allMoooArray[$i]['count_all'],
                                    'count_we' => "0",
                                    'count_they' => $theyValue,
                                    'count_unknown' => $unknownValue
                              );
          $sum_count_all += $allMoooArray[$i]['count_all'];
          $sum_count_they += $theyValue;
          $sum_count_unknown += $unknownValue;
          $sum_all_count_unknown += $unknownValue;
        }else if($compare == true && $compareThey == false && $compareUnknown == false){
            $reArray[$i] = array('name' => $allMoooArray[$i]['name'],
                                    'count_all' => $allMoooArray[$i]['count_all'],
                                    'count_we' => $weValue,
                                    'count_they' => "0",
                                    'count_unknown' => "0"
                              );
          $sum_count_all += $allMoooArray[$i]['count_all'];
          $sum_count_we += $weValue;
        }else if($compare == false && $compareThey == true && $compareUnknown == false){
            $reArray[$i] = array('name' => $allMoooArray[$i]['name'],
                                    'count_all' => $allMoooArray[$i]['count_all'],
                                    'count_we' => "0",
                                    'count_they' => $theyValue,
                                    'count_unknown' =>  "0"
                              );
          $sum_count_all += $allMoooArray[$i]['count_all'];
          $sum_count_they += $theyValue;
        }else if($compare == false && $compareThey == false && $compareUnknown == true){
            $reArray[$i] = array('name' => $allMoooArray[$i]['name'],
                                    'count_all' => $allMoooArray[$i]['count_all'],
                                    'count_we' => "0",
                                    'count_they' => "0",
                                    'count_unknown' => $unknownValue
                              );
          $sum_count_all += $allMoooArray[$i]['count_all'];
          $sum_count_none_canvasser += $unknownValue;
          $sum_all_count_unknown += $unknownValue;
        }
    }
    //var_dump($reArray); exit;

    $render->assign('tam_id', $form['tam_id']);
    $render->assign('sum_count_all', $sum_count_all);
    $render->assign('sum_count_we', $sum_count_we);
    $render->assign('sum_count_they', $sum_count_they);
    $render->assign('sum_count_none_canvasser', $sum_count_none_canvasser);
    $render->assign('sum_all_count_unknown', $sum_all_count_unknown);
    $render->assign('sum_count_unknown', $sum_count_unknown);
    $render->assign('objectArray', $reArray);

  }else if($form['tam_id'] == 0 && $form['dis_id']){
    //Select all
    $query = "     SELECT 	tam_name, COUNT(aco_id) AS count_all, tam_latitude, tam_longitude
                      FROM 
                        zikuladb.pn_degis_contact, zikuladb.zk_votedatacenter_tambon 
                      WHERE aco_district_id = ".$form['dis_id']."
                      AND tam_id = aco_tumbol_id
                      GROUP BY aco_tumbol_id
                      ORDER BY CAST(aco_tumbol_id AS SIGNED INTEGER)";

      $column = array(
                "name", "count_all"
                );

      $result = DBUtil::executeSQL($query);
      $allMoooArray = DBUtil::marshallObjects ($result, $column);

    //Select we
    $query = "SELECT 	tam_name, COUNT(aco_id) AS count_we, tam_latitude, tam_longitude
                      FROM 
                        zikuladb.pn_degis_contact, zikuladb.`zk_votedatacenter_tambon` 
                      WHERE aco_district_id =  ".$form['dis_id']."
                      AND tam_id = aco_tumbol_id
                      AND aco_remarkv =1
                      GROUP BY aco_tumbol_id
                      ORDER BY CAST(aco_tumbol_id AS SIGNED INTEGER)";

      $column = array(
                "name", "count_we"
                );

      $result = DBUtil::executeSQL($query);
      $weMoooArray = DBUtil::marshallObjects ($result, $column);

    //Select they
    $query = "SELECT 	tam_name, COUNT(aco_id) AS count_they, tam_latitude, tam_longitude
                      FROM 
                        zikuladb.pn_degis_contact, zikuladb.`zk_votedatacenter_tambon` 
                      WHERE aco_district_id =  ".$form['dis_id']."
                      AND tam_id = aco_tumbol_id
                      AND aco_remarkv = 0
                      AND aco_remarkv2 =1
                      GROUP BY aco_tumbol_id
                      ORDER BY CAST(aco_tumbol_id AS SIGNED INTEGER)";

      $column = array(
                "name", "count_they"
                );

      $result = DBUtil::executeSQL($query);
      $theyMoooArray = DBUtil::marshallObjects ($result, $column);

    //Select unknown
    $query = "SELECT 	tam_name, COUNT(aco_id) AS count_unknown, tam_latitude, tam_longitude
                      FROM 
                        zikuladb.pn_degis_contact, zikuladb.`zk_votedatacenter_tambon` 
                      WHERE aco_district_id =  ".$form['dis_id']."
                      AND tam_id = aco_tumbol_id
                      AND aco_remarkv =0
                      AND aco_remarkv2 =0
                      GROUP BY aco_tumbol_id
                      ORDER BY CAST(aco_tumbol_id AS SIGNED INTEGER)";

      $column = array(
                "name", "count_unknown"
                );

      $result = DBUtil::executeSQL($query);
      $unknownMoooArray = DBUtil::marshallObjects ($result, $column);

      $reArray = array();
      
      $sum_count_all = 0;
      $sum_count_we = 0;
      $sum_count_they = 0;
      $sum_count_unknown = 0;
      $sum_count_none_canvasser = 0;
      for($i=0; $i<count($allMoooArray); $i++){
        $compare = false;
        $compareThey = false;
        $compareUnknown = false;
        //Comoare we
        for($j=0; $j<count($weMoooArray); $j++){
          if($weMoooArray[$j]['name'] == $allMoooArray[$i]['name']){
            //echo $weMoooArray[$j]['aco_addr_moo']." with ".$allMoooArray[$i]['aco_addr_moo']."<br>";
            $compare = true;
            $weValue = $weMoooArray[$j]['count_we'];
          }
        }

        //Comoare they
        for($k=0; $k<count($theyMoooArray); $k++){
          if($theyMoooArray[$k]['name'] == $allMoooArray[$i]['name']){
            //echo $theyMoooArray[$k]['aco_addr_moo']." with ".$allMoooArray[$i]['aco_addr_moo']."<br>";
            $compareThey = true;
            $theyValue = $theyMoooArray[$k]['count_they'];
          }
        }

        //Comoare unknow
        for($l=0; $l<count($unknownMoooArray); $l++){
          if($unknownMoooArray[$l]['name'] == $allMoooArray[$i]['name']){
            //echo $unknownMoooArray[$l]['aco_addr_moo']." with ".$allMoooArray[$i]['aco_addr_moo']."<br>";
            $compareUnknown = true;
            $unknownValue = $unknownMoooArray[$l]['count_unknown'];
          }
        }

        if($compare == true && $compareThey == true && $compareUnknown == true){
            $reArray[$i] = array('name' => $allMoooArray[$i]['name'],
                                    'count_all' => $allMoooArray[$i]['count_all'],
                                    'count_we' => $weValue,
                                    'count_they' => $theyValue,
                                    'count_unknown' => $unknownValue
                              );
          $sum_count_all += $allMoooArray[$i]['count_all'];
          $sum_count_we += $weValue;
          $sum_count_they += $theyValue;
          $sum_count_unknown += $unknownValue;
          $sum_all_count_unknown += $unknownValue;
        }else if($compare == false && $compareThey == true && $compareUnknown == true){
            $reArray[$i] = array('name' => $allMoooArray[$i]['name'],
                                    'count_all' => $allMoooArray[$i]['count_all'],
                                    'count_we' => "0",
                                    'count_they' => $theyValue,
                                    'count_unknown' => $unknownValue
                              );
          $sum_count_all += $allMoooArray[$i]['count_all'];
          $sum_count_they += $theyValue;
          $sum_count_unknown += $unknownValue;
          $sum_all_count_unknown += $unknownValue;
        }else if($compare == true && $compareThey == false && $compareUnknown == true){
            $reArray[$i] = array('name' => $allMoooArray[$i]['name'],
                                    'count_all' => $allMoooArray[$i]['count_all'],
                                    'count_we' => $weValue,
                                    'count_they' => "0",
                                    'count_unknown' => $unknownValue
                              );
          $sum_count_all += $allMoooArray[$i]['count_all'];
          $sum_count_we += $weValue;
          $sum_count_unknown += $unknownValue;
          $sum_all_count_unknown += $unknownValue;
        }else if($compare == true && $compareThey == true && $compareUnknown == false){
            $reArray[$i] = array('name' => $allMoooArray[$i]['name'],
                                    'count_all' => $allMoooArray[$i]['count_all'],
                                    'count_we' => $weValue,
                                    'count_they' => $theyValue,
                                    'count_unknown' => "0"
                              );
          $sum_count_all += $allMoooArray[$i]['count_all'];
          $sum_count_we += $weValue;
          $sum_count_they += $theyValue;
        }else if($compare == false && $compareThey == true && $compareUnknown == true){
            $reArray[$i] = array('name' => $allMoooArray[$i]['name'],
                                    'count_all' => $allMoooArray[$i]['count_all'],
                                    'count_we' => "0",
                                    'count_they' => $theyValue,
                                    'count_unknown' => $unknownValue
                              );
          $sum_count_all += $allMoooArray[$i]['count_all'];
          $sum_count_they += $theyValue;
          $sum_count_unknown += $unknownValue;
          $sum_all_count_unknown += $unknownValue;
        }else if($compare == true && $compareThey == false && $compareUnknown == false){
            $reArray[$i] = array('name' => $allMoooArray[$i]['name'],
                                    'count_all' => $allMoooArray[$i]['count_all'],
                                    'count_we' => $weValue,
                                    'count_they' => "0",
                                    'count_unknown' => "0"
                              );
          $sum_count_all += $allMoooArray[$i]['count_all'];
          $sum_count_we += $weValue;
        }else if($compare == false && $compareThey == true && $compareUnknown == false){
            $reArray[$i] = array('name' => $allMoooArray[$i]['name'],
                                    'count_all' => $allMoooArray[$i]['count_all'],
                                    'count_we' => "0",
                                    'count_they' => $theyValue,
                                    'count_unknown' =>  "0"
                              );
          $sum_count_all += $allMoooArray[$i]['count_all'];
          $sum_count_they += $theyValue;
        }else if($compare == false && $compareThey == false && $compareUnknown == true){
            $reArray[$i] = array('name' => $allMoooArray[$i]['name'],
                                    'count_all' => $allMoooArray[$i]['count_all'],
                                    'count_we' => "0",
                                    'count_they' => "0",
                                    'count_unknown' => $unknownValue
                              );
          $sum_count_all += $allMoooArray[$i]['count_all'];
          $sum_count_none_canvasser += $unknownValue;
          $sum_all_count_unknown += $unknownValue;
        }
    }
    //var_dump($reArray); exit;
    $render->assign('sum_count_all', $sum_count_all);
    $render->assign('sum_count_we', $sum_count_we);
    $render->assign('sum_count_they', $sum_count_they);
    $render->assign('sum_count_none_canvasser', $sum_count_none_canvasser);
    $render->assign('sum_all_count_unknown', $sum_all_count_unknown);
    $render->assign('sum_count_unknown', $sum_count_unknown);
    $render->assign('objectArray', $reArray);
  }else if($form['khet_id'] && $form['tam_id'] == 0 && $form['dis_id'] == 0){

    if($form[khet_id] == 1 && $form['pro_id'] == 54){
      //อำเภอเมืองแพร่ (นาจักร, น้ำชำ, ป่าแดง, ทุ่งโฮ้ง, เหมืองหม้อ, ป่าแมต, บ้านถิ่น ,สวนเขื่อน ,ทุ่งกวาว ,ช่อแฮ ,ร่องฟอง ,กาญจนา ,ในเวียง) ,
      //อำเภอสูงเม่น&เทศบาลสูงเม่น(ยกเว้น หัวฝาย บ้านปง)
      

      
      $query = "SELECT 	tam_name, COUNT(aco_id) AS count_muang_all, tam_latitude, tam_longitude
                        FROM 
                          zikuladb.pn_degis_contact, zikuladb.`zk_votedatacenter_tambon` 
                        WHERE aco_district_id =  5401
                        AND (
                              tam_id != 540109 || 
                              tam_id != 540108 || 
                              tam_id != 540114 || 
                              tam_id != 540117 || 
                              tam_id != 540113 || 
                              tam_id != 540116 || 
                              tam_id != 540107 ||
                              tam_id != 540101
                            )
                        AND tam_id = aco_tumbol_id
                        GROUP BY tam_name
                        ORDER BY tam_name";
      $column = array(
                "name", "count_muang_all"
                );
      $result = DBUtil::executeSQL($query);
      $allMuangArray = DBUtil::marshallObjects ($result, $column);


      //////////////////////////////////////////////////////////////////////
      //////////////////////////////////////////////////////////////////////
      //
      // Query khet1 we
      //
      //////////////////////////////////////////////////////////////////////
      //////////////////////////////////////////////////////////////////////
      //Get we from 5401 อำเภอเมืองแพร่่
      $query = "SELECT 	tam_name, COUNT(aco_id) AS count_muang_we, tam_latitude, tam_longitude
                        FROM 
                          zikuladb.pn_degis_contact, zikuladb.`zk_votedatacenter_tambon` 
                        WHERE aco_district_id =  5401
                        AND (
                              tam_id != 540109 || 
                              tam_id != 540108 || 
                              tam_id != 540114 || 
                              tam_id != 540117 || 
                              tam_id != 540113 || 
                              tam_id != 540116 || 
                              tam_id != 540107 ||
                              tam_id != 540101
                            )
                        AND tam_id = aco_tumbol_id
                        AND aco_remarkv =1 
                        GROUP BY tam_name
                        ORDER BY tam_name";
      $column = array(
                "name", "count_muang_we"
                );
      $result = DBUtil::executeSQL($query);
      $weMuangArray = DBUtil::marshallObjects ($result, $column);

      //Get they from 5401 อำเภอเมืองแพร่่
      $query = "SELECT 	tam_name, COUNT(aco_id) AS count_muang_they, tam_latitude, tam_longitude
                        FROM 
                          zikuladb.pn_degis_contact, zikuladb.`zk_votedatacenter_tambon` 
                        WHERE aco_district_id =  5401
                        AND (
                              tam_id != 540109 || 
                              tam_id != 540108 || 
                              tam_id != 540114 || 
                              tam_id != 540117 || 
                              tam_id != 540113 || 
                              tam_id != 540116 || 
                              tam_id != 540107 ||
                              tam_id != 540101
                            )
                        AND tam_id = aco_tumbol_id
                        AND aco_remarkv = 0
                        AND aco_remarkv2 =1
                        GROUP BY tam_name
                        ORDER BY tam_name";
      $column = array(
                "name", "count_muang_they"
                );
      $result = DBUtil::executeSQL($query);
      $theyMuangArray = DBUtil::marshallObjects ($result, $column);

      //Get data from 5401 อำเภอเมืองแพร่่
      $query = "SELECT 	tam_name, COUNT(aco_id) AS count_muang_unknown, tam_latitude, tam_longitude
                        FROM 
                          zikuladb.pn_degis_contact, zikuladb.`zk_votedatacenter_tambon` 
                        WHERE aco_district_id =  5401
                        AND (
                              tam_id != 540109 || 
                              tam_id != 540108 || 
                              tam_id != 540114 || 
                              tam_id != 540117 || 
                              tam_id != 540113 || 
                              tam_id != 540116 || 
                              tam_id != 540107 ||
                              tam_id != 540101
                            )
                        AND tam_id = aco_tumbol_id
                        AND aco_remarkv =0
                        AND aco_remarkv2 =0
                        GROUP BY tam_name
                        ORDER BY tam_name";
      $column = array(
                "name", "count_muang_unknown"
                );
      $result = DBUtil::executeSQL($query);
      $unknownMuangArray = DBUtil::marshallObjects ($result, $column);

      /////////////////////////////////////
      //Sum muang khet2
      /////////////////////////////////////
      $sum_count_muang_all = 0;
      foreach($allMuangArray as $item){
        //echo $item['name']."\t".$item['count_muang_all']."<br>";
        $sum_count_muang_all += $item['count_muang_all'];
      }
      //echo "all    \t".$sum_count_muang_all."<br>";

      $sum_count_muang_we = 0;
      foreach($weMuangArray as $item){
        //echo $item['name']."::".$item['count_muang_we']."<br>";
        $sum_count_muang_we += $item['count_muang_we'];
      }
      //echo "we \t".$sum_count_muang_we."<br>";

      $sum_count_muang_they = 0;
      foreach($theyMuangArray as $item){
        //echo $item['name']."::".$item['count_muang_they']."<br>";
        $sum_count_muang_they += $item['count_muang_they'];
      }
      //echo "they \t".$sum_count_muang_they."<br>";

      $sum_count_muang_unknown = 0;
      foreach($unknownMuangArray as $item){
        //echo $item['name']."::".$item['count_muang_unknown']."<br>";
        $sum_count_muang_unknown += $item['count_muang_unknown'];
      }
      //echo "unknown ".$sum_count_muang_unknown."<br>";

      //Muang merge array
      for($i=0; $i<count($allMuangArray); $i++){
        $compare = false;
        $compareThey = false;
        $compareUnknown = false;
        $allMuangArrayName = $allMuangArray[$i]['name'];
        $allMaungArrayCount = $allMuangArray[$i]['count_muang_all'];

        //Compare we
        for($j=0; $j<count($weMuangArray); $j++){
          if($weMuangArray[$j]['name'] == $allMuangArrayName){
            //echo $weMuangArray[$j]['aco_addr_moo']." with ".$allMuangArray[$i]['aco_addr_moo']."<br>";
            $compare = true;
            $weMuangValue = $weMuangArray[$j]['count_muang_we'];
          }
        }

        //Compare they
        for($k=0; $k<count($theyMuangArray); $k++){
          if($theyMuangArray[$k]['name'] == $allMuangArrayName){
            //echo $theyMuangArray[$k]['aco_addr_moo']." with ".$allMuangArray[$i]['aco_addr_moo']."<br>";
            $compareThey = true;
            $theyMuangValue = $theyMuangArray[$k]['count_muang_they'];
          }
        }

        //Compare unknow
        for($l=0; $l<count($unknownMuangArray); $l++){
          if($unknownMuangArray[$l]['name'] == $allMuangArrayName){
            //echo $unknownMuangArray[$l]['aco_addr_moo']." with ".$allMuangArray[$i]['aco_addr_moo']."<br>";
            $compareUnknown = true;
            $unknownMuangValue = $unknownMuangArray[$l]['count_muang_unknown'];
          }
        }

        if($compare == true && $compareThey == true && $compareUnknown == true){
            $reMuangArray[$i] = array('name' => $allMuangArrayName,
                                    'count_all' => $allMaungArrayCount,
                                    'count_we' => $weMuangValue,
                                    'count_they' => $theyMuangValue,
                                    'count_unknown' => $unknownMuangValue
                              );
          $sum_count_all += $allMaungArrayCount;
          $sum_count_we += $weMuangValue;
          $sum_count_they += $theyMuangValue;
          $sum_count_unknown += $unknownValue;
          $sum_all_count_unknown += $unknownMuangValue;
        }else if($compare == false && $compareThey == true && $compareUnknown == true){
            $reMuangArray[$i] = array('name' => $allMuangArrayName,
                                    'count_all' => $allMaungArrayCount,
                                    'count_we' => "0",
                                    'count_they' => $theyMuangValue,
                                    'count_unknown' => $unknownMuangValue
                              );
          $sum_count_all += $allMaungArrayCount;
          $sum_count_they += $theyMuangValue;
          $sum_count_unknown += $unknownValue;
          $sum_all_count_unknown += $unknownMuangValue;
        }else if($compare == true && $compareThey == false && $compareUnknown == true){
            $reMuangArray[$i] = array('name' => $allMuangArrayName,
                                    'count_all' => $allMaungArrayCount,
                                    'count_we' => $weMuangValue,
                                    'count_they' => "0",
                                    'count_unknown' => $unknownMuangValue
                              );
          $sum_count_all += $allMaungArrayCount;
          $sum_count_we += $weMuangValue;
          $sum_count_unknown += $unknownMuangValue;
          $sum_all_count_unknown += $unknownMuangValue;
        }else if($compare == true && $compareThey == true && $compareUnknown == false){
            $reMuangArray[$i] = array('name' => $allMuangArrayName,
                                    'count_all' => $allMaungArrayCount,
                                    'count_we' => $weMuangValue,
                                    'count_they' => $theyMuangValue,
                                    'count_unknown' => "0"
                              );
          $sum_count_all += $allMaungArrayCount;
          $sum_count_we += $weMuangValue;
          $sum_count_they += $theyMuangValue;
        }else if($compare == false && $compareThey == true && $compareUnknown == true){
            $reMuangArray[$i] = array('name' => $allMuangArrayName,
                                    'count_all' => $allMaungArrayCount,
                                    'count_we' => "0",
                                    'count_they' => $theyMuangValue,
                                    'count_unknown' => $unknownMuangValue
                              );
          $sum_count_all += $allMaungArrayCount;
          $sum_count_they += $theyMuangValue;
          $sum_count_unknown += $unknownValue;
          $sum_all_count_unknown += $unknownMuangValue;
        }else if($compare == true && $compareThey == false && $compareUnknown == false){
            $reMuangArray[$i] = array('name' => $allMuangArrayName,
                                    'count_all' => $allMaungArrayCount,
                                    'count_we' => $weMuangValue,
                                    'count_they' => "0",
                                    'count_unknown' => "0"
                              );
          $sum_count_all += $allMaungArrayCount;
          $sum_count_we += $weMuangValue;
        }else if($compare == false && $compareThey == true && $compareUnknown == false){
            $reMuangArray[$i] = array('name' => $allMuangArrayName,
                                    'count_all' => $allMaungArrayCount,
                                    'count_we' => "0",
                                    'count_they' => $theyMuangValue,
                                    'count_unknown' =>  "0"
                              );
          $sum_count_all += $allMaungArrayCount;
          $sum_count_they += $theyMuangValue;
        }else if($compare == false && $compareThey == false && $compareUnknown == true){
            $reMuangArray[$i] = array('name' => $allMuangArrayName,
                                    'count_all' => $allMaungArrayCount,
                                    'count_we' => "0",
                                    'count_they' => "0",
                                    'count_unknown' => $unknownMuangValue
                              );
          $sum_count_all += $allMaungArrayCount;
          $sum_count_none_canvasser += $unknownMuangValue;
          $sum_all_count_unknown += $unknownMuangValue;
        }
      }

      //Extension Naimuang data
      $reMuangArray[count($allMuangArray)] = array('name' => "ในเวียง",
                                                    'count_all' => "12959",
                                                    'count_we' => "4523",
                                                    'count_they' => "2575",
                                                    'count_unknown' => "5861"
                                              );
      $sum_count_all += 12959;
      $sum_count_we += 4523;
      $sum_count_they += 2575;
      $sum_count_unknown += 5861;
      $sum_all_count_unknown += 5861;

      $sum_count_muang_all +=12959;
      $sum_count_muang_we += 4523;
      $sum_count_muang_they += 2575;
      $sum_count_muang_unknown += 5861;


      //var_dump($reMuangArray); exit;
      $render->assign('district_muang', "อ.เมือง");
      $render->assign('sum_count_all', $sum_count_all);
      $render->assign('sum_count_we', $sum_count_we);
      $render->assign('sum_count_they', $sum_count_they);
      $render->assign('sum_count_none_canvasser', $sum_count_none_canvasser);
      $render->assign('sum_all_count_unknown', $sum_all_count_unknown);
      $render->assign('sum_count_unknown', $sum_count_unknown);
      $render->assign('objectArray', $reMuangArray);


      
      //////////////////////////////////////////////////////////////////////
      //////////////////////////////////////////////////////////////////////
      //
      // Query khet1 all
      //
      //////////////////////////////////////////////////////////////////////
      //////////////////////////////////////////////////////////////////////
        //Get data from 5406 สอง
        $query = "SELECT 	tam_name, COUNT(aco_id) AS count_sungmen_all, tam_latitude, tam_longitude
                          FROM 
                            zikuladb.pn_degis_contact, zikuladb.`zk_votedatacenter_tambon` 
                          WHERE (aco_district_id =  5404 || aco_district_id =  5417)
                          AND aco_tumbol_id != 540403 
                          AND aco_tumbol_id != 540407
                          AND tam_id = aco_tumbol_id
                          GROUP BY tam_name
                          ORDER BY tam_name";
        $column = array(
                  "name", "count_sungmen_all"
                  );

        $result = DBUtil::executeSQL($query);
        $alSungmenArray = DBUtil::marshallObjects ($result, $column);




        //Get data from 5406 สอง
        $query = "SELECT 	tam_name, COUNT(aco_id) AS count_sungmen_we, tam_latitude, tam_longitude
                          FROM 
                            zikuladb.pn_degis_contact, zikuladb.`zk_votedatacenter_tambon` 
                          WHERE (aco_district_id =  5404 || aco_district_id =  5417)
                          AND aco_tumbol_id != 540403 
                          AND aco_tumbol_id != 540407
                          AND tam_id = aco_tumbol_id
                          AND aco_remarkv =1
                          GROUP BY tam_name
                          ORDER BY tam_name";
        $column = array(
                  "name", "count_sungmen_we"
                  );

        $result = DBUtil::executeSQL($query);
        $weSungmenArray = DBUtil::marshallObjects ($result, $column);




        //Get data from 5406 สอง
        $query = "SELECT 	tam_name, COUNT(aco_id) AS count_sungmen_they, tam_latitude, tam_longitude
                          FROM 
                            zikuladb.pn_degis_contact, zikuladb.`zk_votedatacenter_tambon` 
                          WHERE (aco_district_id =  5404 || aco_district_id =  5417)
                          AND aco_tumbol_id != 540403 
                          AND aco_tumbol_id != 540407
                          AND tam_id = aco_tumbol_id
                          AND aco_remarkv = 0
                          AND aco_remarkv2 =1
                          GROUP BY tam_name
                          ORDER BY tam_name";
        $column = array(
                  "name", "count_sungmen_they"
                  );

        $result = DBUtil::executeSQL($query);
        $theySungmenArray = DBUtil::marshallObjects ($result, $column);




        //Get data from 5406 สอง
        $query = "SELECT 	tam_name, COUNT(aco_id) AS count_sungmen_unknown, tam_latitude, tam_longitude
                          FROM 
                            zikuladb.pn_degis_contact, zikuladb.`zk_votedatacenter_tambon` 
                          WHERE (aco_district_id =  5404 || aco_district_id =  5417)
                          AND aco_tumbol_id != 540403 
                          AND aco_tumbol_id != 540407
                          AND tam_id = aco_tumbol_id
                          AND aco_remarkv =0
                          AND aco_remarkv2 =0
                          GROUP BY tam_name
                          ORDER BY tam_name";
        $column = array(
                  "name", "count_sungmen_unknown"
                  );

        $result = DBUtil::executeSQL($query);
        $unknownSungmenArray = DBUtil::marshallObjects ($result, $column);


        //Sungmen merge array
        for($i=0; $i<count($alSungmenArray); $i++){
          $compare = false;
          $compareThey = false;
          $compareUnknown = false;
          $alSungmenArrayName = $alSungmenArray[$i]['name'];
          $alSungmenArrayCount = $alSungmenArray[$i]['count_sungmen_all'];

          //Compare we
          for($j=0; $j<count($weSungmenArray); $j++){
            if($weSungmenArray[$j]['name'] == $alSungmenArrayName){
              //echo $weSungmenArray[$j]['aco_addr_moo']." with ".$alSungmenArray[$i]['aco_addr_moo']."<br>";
              $compare = true;
              $weSungmenValue = $weSungmenArray[$j]['count_sungmen_we'];
            }
          }

          //Compare they
          for($k=0; $k<count($theySungmenArray); $k++){
            if($theySungmenArray[$k]['name'] == $alSungmenArrayName){
              //echo $theySungmenArray[$k]['aco_addr_moo']." with ".$alSungmenArray[$i]['aco_addr_moo']."<br>";
              $compareThey = true;
              $theySungmenValue = $theySungmenArray[$k]['count_sungmen_they'];
            }
          }

          //Compare unknow
          for($l=0; $l<count($unknownSungmenArray); $l++){
            if($unknownSungmenArray[$l]['name'] == $alSungmenArrayName){
              //echo $unknownSungmenArray[$l]['aco_addr_moo']." with ".$alSungmenArray[$i]['aco_addr_moo']."<br>";
              $compareUnknown = true;
              $unknownSungmenValue = $unknownSungmenArray[$l]['count_sungmen_unknown'];
            }
          }

          if($compare == true && $compareThey == true && $compareUnknown == true){
              $reSungmenArray[$i] = array('name' => $alSungmenArrayName,
                                      'count_sungmen_all' => $alSungmenArrayCount,
                                      'count_sungmen_we' => $weSungmenValue,
                                      'count_sungmen_they' => $theySungmenValue,
                                      'count_sungmen_unknown' => $unknownSungmenValue
                                );
            $sum_count_sungmen_all += $alSungmenArrayCount;
            $sum_count_sungmen_we += $weSungmenValue;
            $sum_count_sungmen_they += $theySungmenValue;
            $sum_count_sungmen_unknown += $unknownSungmenValue;
            $sum_all_count_sungmen_unknown += $unknownSungmenValue;
          }else if($compare == false && $compareThey == true && $compareUnknown == true){
              $reSungmenArray[$i] = array('name' => $alSungmenArrayName,
                                      'count_sungmen_all' => $alSungmenArrayCount,
                                      'count_sungmen_we' => "0",
                                      'count_sungmen_they' => $theySungmenValue,
                                      'count_sungmen_unknown' => $unknownSungmenValue
                                );
            $sum_count_sungmen_all += $alSungmenArrayCount;
            $sum_count_sungmen_they += $theySungmenValue;
            $sum_count_sungmen_unknown += $unknownSungmenValue;
            $sum_all_count_sungmen_unknown += $unknownSungmenValue;
          }else if($compare == true && $compareThey == false && $compareUnknown == true){
              $reSungmenArray[$i] = array('name' => $alSungmenArrayName,
                                      'count_sungmen_all' => $alSungmenArrayCount,
                                      'count_sungmen_we' => $weSungmenValue,
                                      'count_sungmen_they' => "0",
                                      'count_sungmen_unknown' => $unknownSungmenValue
                                );
            $sum_count_sungmen_all += $alSungmenArrayCount;
            $sum_count_sungmen_we += $weSungmenValue;
            $sum_count_sungmen_unknown += $unknownSungmenValue;
            $sum_all_count_sungmen_unknown += $unknownSungmenValue;
          }else if($compare == true && $compareThey == true && $compareUnknown == false){
              $reSungmenArray[$i] = array('name' => $alSungmenArrayName,
                                      'count_sungmen_all' => $alSungmenArrayCount,
                                      'count_sungmen_we' => $weSungmenValue,
                                      'count_sungmen_they' => $theySungmenValue,
                                      'count_sungmen_unknown' => "0"
                                );
            $sum_count_sungmen_all += $alSungmenArrayCount;
            $sum_count_sungmen_we += $weSungmenValue;
            $sum_count_sungmen_they += $theySungmenValue;
          }else if($compare == false && $compareThey == true && $compareUnknown == true){
              $reSungmenArray[$i] = array('name' => $alSungmenArrayName,
                                      'count_sungmen_all' => $alSungmenArrayCount,
                                      'count_sungmen_we' => "0",
                                      'count_sungmen_they' => $theySungmenValue,
                                      'count_sungmen_unknown' => $unknownSungmenValue
                                );
            $sum_count_sungmen_all += $alSungmenArrayCount;
            $sum_count_sungmen_they += $theySungmenValue;
            $sum_count_sungmen_unknown += $unknownSungmenValue;
            $sum_all_count_sungmen_unknown += $unknownSungmenValue;
          }else if($compare == true && $compareThey == false && $compareUnknown == false){
              $reSungmenArray[$i] = array('name' => $alSungmenArrayName,
                                      'count_sungmen_all' => $alSungmenArrayCount,
                                      'count_sungmen_we' => $weSungmenValue,
                                      'count_sungmen_they' => "0",
                                      'count_sungmen_unknown' => "0"
                                );
            $sum_count_sungmen_all += $alSungmenArrayCount;
            $sum_count_sungmen_we += $weSungmenValue;
          }else if($compare == false && $compareThey == true && $compareUnknown == false){
              $reSungmenArray[$i] = array('name' => $alSungmenArrayName,
                                      'count_sungmen_all' => $alSungmenArrayCount,
                                      'count_sungmen_we' => "0",
                                      'count_sungmen_they' => $theySungmenValue,
                                      'count_sungmen_unknown' =>  "0"
                                );
            $sum_count_sungmen_all += $alSungmenArrayCount;
            $sum_count_sungmen_they += $theySungmenValue;
          }else if($compare == false && $compareThey == false && $compareUnknown == true){
              $reSungmenArray[$i] = array('name' => $alSungmenArrayName,
                                      'count_sungmen_all' => $alSungmenArrayCount,
                                      'count_sungmen_we' => "0",
                                      'count_sungmen_they' => "0",
                                      'count_sungmen_unknown' => $unknownSungmenValue
                                );
            $sum_count_sungmen_all += $alSungmenArrayCount;
            $sum_count_sungmen_none_canvasser += $unknownSungmenValue;
            $sum_all_count_sungmen_unknown += $unknownSungmenValue;
          }
        }

      //var_dump($reSungmenArray['count_sungmen_all']); exit;
      $render->assign('reportSungmen', "sungmen");
      $render->assign('district_sungmen', "อ.สูงเม่น");
      $render->assign('sum_count_sungmen_all', $sum_count_sungmen_all);
      $render->assign('sum_count_sungmen_we', $sum_count_sungmen_we);
      $render->assign('sum_count_sungmen_they', $sum_count_sungmen_they);
      $render->assign('sum_count_sungmen_none_canvasser', $sum_count_sungmen_none_canvasser);
      $render->assign('sum_all_count_sungmen_unknown', $sum_all_count_sungmen_unknown);
      $render->assign('sum_count_sungmen_unknown', $sum_count_sungmen_unknown);
      $render->assign('objectSungmenArray', $reSungmenArray);


      $render->assign('total_sum_we', $sum_count_muang_we+$sum_count_sungmen_we);
      $render->assign('total_sum_they', $sum_count_muang_they+$sum_count_sungmen_they);
      $render->assign('total_sum_unknown', $sum_count_muang_unknown+$sum_count_sungmen_unknown);



    }else if($form['khet_id'] == 2 && $form['pro_id'] == 54){
      //อำเภอเมืองแพร่ (เฉพาะตำบลห้วยม้า, ตำบลแม่หล่าย, ตำบลแม่คำมี, ตำบลแม่ยม, ตำบลวังหงส์, ตำบลท่าข้าม และตำบลวังธง) อำเภอสอง, อำเภอร้องกวาง และอำเภอหนองม่วงไข่
      //            540109       , 540108   ,    540114,   540117,  540113   , 540116 , 540107  ,5406&5417  ,5402&5415   , 5408 & 5419
      //////////////////////////////////////////////////////////////////////
      //////////////////////////////////////////////////////////////////////
      //
      // Query khet2 all
      //
      //////////////////////////////////////////////////////////////////////
      //////////////////////////////////////////////////////////////////////
      //Get all from 5401 อำเภอเมืองแพร่่
      $query = "SELECT 	tam_name, COUNT(aco_id) AS count_muang_all
                        FROM 
                          zikuladb.pn_degis_contact, zikuladb.`zk_votedatacenter_tambon` 
                        WHERE aco_district_id =  5401
                        AND (
                              tam_id = 540109 || 
                              tam_id = 540108 || 
                              tam_id = 540114 || 
                              tam_id = 540117 || 
                              tam_id = 540113 || 
                              tam_id = 540116 || 
                              tam_id = 540107 
                            )
                        AND tam_id = aco_tumbol_id
                        GROUP BY tam_name
                        ORDER BY tam_name";
      $column = array(
                "name", "count_muang_all"
                );
      $result = DBUtil::executeSQL($query);
      $allMuangArray = DBUtil::marshallObjects ($result, $column);


      //////////////////////////////////////////////////////////////////////
      //////////////////////////////////////////////////////////////////////
      //
      // Query khet2 we
      //
      //////////////////////////////////////////////////////////////////////
      //////////////////////////////////////////////////////////////////////
      //Get we from 5401 อำเภอเมืองแพร่่
      $query = "SELECT 	tam_name, COUNT(aco_id) AS count_muang_we, tam_latitude, tam_longitude
                        FROM 
                          zikuladb.pn_degis_contact, zikuladb.`zk_votedatacenter_tambon` 
                        WHERE aco_district_id =  5401
                        AND (
                              tam_id = 540109 || 
                              tam_id = 540108 || 
                              tam_id = 540114 || 
                              tam_id = 540117 || 
                              tam_id = 540113 || 
                              tam_id = 540116 || 
                              tam_id = 540107 
                            )
                        AND tam_id = aco_tumbol_id
                        AND aco_remarkv =1 
                        GROUP BY tam_name
                        ORDER BY tam_name";
      $column = array(
                "name", "count_muang_we"
                );
      $result = DBUtil::executeSQL($query);
      $weMuangArray = DBUtil::marshallObjects ($result, $column);

      //Get they from 5401 อำเภอเมืองแพร่่
      $query = "SELECT 	tam_name, COUNT(aco_id) AS count_muang_they, tam_latitude, tam_longitude
                        FROM 
                          zikuladb.pn_degis_contact, zikuladb.`zk_votedatacenter_tambon` 
                        WHERE aco_district_id =  5401
                        AND (
                              tam_id = 540109 || 
                              tam_id = 540108 || 
                              tam_id = 540114 || 
                              tam_id = 540117 || 
                              tam_id = 540113 || 
                              tam_id = 540116 || 
                              tam_id = 540107 
                            )
                        AND tam_id = aco_tumbol_id
                        AND aco_remarkv = 0
                        AND aco_remarkv2 =1
                        GROUP BY tam_name
                        ORDER BY tam_name";
      $column = array(
                "name", "count_muang_they"
                );
      $result = DBUtil::executeSQL($query);
      $theyMuangArray = DBUtil::marshallObjects ($result, $column);

      //Get data from 5401 อำเภอเมืองแพร่่
      $query = "SELECT 	tam_name, COUNT(aco_id) AS count_muang_unknown, tam_latitude, tam_longitude
                        FROM 
                          zikuladb.pn_degis_contact, zikuladb.`zk_votedatacenter_tambon` 
                        WHERE aco_district_id =  5401
                        AND (
                              tam_id = 540109 || 
                              tam_id = 540108 || 
                              tam_id = 540114 || 
                              tam_id = 540117 || 
                              tam_id = 540113 || 
                              tam_id = 540116 || 
                              tam_id = 540107 
                            )
                        AND tam_id = aco_tumbol_id
                        AND aco_remarkv =0
                        AND aco_remarkv2 =0
                        GROUP BY tam_name
                        ORDER BY tam_name";
      $column = array(
                "name", "count_muang_unknown"
                );
      $result = DBUtil::executeSQL($query);
      $unknownMuangArray = DBUtil::marshallObjects ($result, $column);

      /////////////////////////////////////
      //Sum muang khet2
      /////////////////////////////////////
      $sum_count_muang_all = 0;
      foreach($allMuangArray as $item){
        //echo $item['name']."\t".$item['count_muang_all']."<br>";
        $sum_count_muang_all += $item['count_muang_all'];
      }
      //echo "all    \t".$sum_count_muang_all."<br>";

      $sum_count_muang_we = 0;
      foreach($weMuangArray as $item){
        //echo $item['name']."::".$item['count_muang_we']."<br>";
        $sum_count_muang_we += $item['count_muang_we'];
      }
      //echo "we \t".$sum_count_muang_we."<br>";

      $sum_count_muang_they = 0;
      foreach($theyMuangArray as $item){
        //echo $item['name']."::".$item['count_muang_they']."<br>";
        $sum_count_muang_they += $item['count_muang_they'];
      }
      //echo "they \t".$sum_count_muang_they."<br>";

      $sum_count_muang_unknown = 0;
      foreach($unknownMuangArray as $item){
        //echo $item['name']."::".$item['count_muang_unknown']."<br>";
        $sum_count_muang_unknown += $item['count_muang_unknown'];
      }
      //echo "unknown ".$sum_count_muang_unknown."<br>";

      //Muang merge array
      for($i=0; $i<count($allMuangArray); $i++){
        $compare = false;
        $compareThey = false;
        $compareUnknown = false;
        $allMuangArrayName = $allMuangArray[$i]['name'];
        $allMaungArrayCount = $allMuangArray[$i]['count_muang_all'];

        //Compare we
        for($j=0; $j<count($weMuangArray); $j++){
          if($weMuangArray[$j]['name'] == $allMuangArrayName){
            //echo $weMuangArray[$j]['aco_addr_moo']." with ".$allMuangArray[$i]['aco_addr_moo']."<br>";
            $compare = true;
            $weMuangValue = $weMuangArray[$j]['count_muang_we'];
          }
        }

        //Compare they
        for($k=0; $k<count($theyMuangArray); $k++){
          if($theyMuangArray[$k]['name'] == $allMuangArrayName){
            //echo $theyMuangArray[$k]['aco_addr_moo']." with ".$allMuangArray[$i]['aco_addr_moo']."<br>";
            $compareThey = true;
            $theyMuangValue = $theyMuangArray[$k]['count_muang_they'];
          }
        }

        //Compare unknow
        for($l=0; $l<count($unknownMuangArray); $l++){
          if($unknownMuangArray[$l]['name'] == $allMuangArrayName){
            //echo $unknownMuangArray[$l]['aco_addr_moo']." with ".$allMuangArray[$i]['aco_addr_moo']."<br>";
            $compareUnknown = true;
            $unknownMuangValue = $unknownMuangArray[$l]['count_muang_unknown'];
          }
        }

        if($compare == true && $compareThey == true && $compareUnknown == true){
            $reMuangArray[$i] = array('name' => $allMuangArrayName,
                                    'count_all' => $allMaungArrayCount,
                                    'count_we' => $weMuangValue,
                                    'count_they' => $theyMuangValue,
                                    'count_unknown' => $unknownMuangValue
                              );
          $sum_count_all += $allMaungArrayCount;
          $sum_count_we += $weMuangValue;
          $sum_count_they += $theyMuangValue;
          $sum_count_unknown += $unknownValue;
          $sum_all_count_unknown += $unknownMuangValue;
        }else if($compare == false && $compareThey == true && $compareUnknown == true){
            $reMuangArray[$i] = array('name' => $allMuangArrayName,
                                    'count_all' => $allMaungArrayCount,
                                    'count_we' => "0",
                                    'count_they' => $theyMuangValue,
                                    'count_unknown' => $unknownMuangValue
                              );
          $sum_count_all += $allMaungArrayCount;
          $sum_count_they += $theyMuangValue;
          $sum_count_unknown += $unknownValue;
          $sum_all_count_unknown += $unknownMuangValue;
        }else if($compare == true && $compareThey == false && $compareUnknown == true){
            $reMuangArray[$i] = array('name' => $allMuangArrayName,
                                    'count_all' => $allMaungArrayCount,
                                    'count_we' => $weMuangValue,
                                    'count_they' => "0",
                                    'count_unknown' => $unknownMuangValue
                              );
          $sum_count_all += $allMaungArrayCount;
          $sum_count_we += $weMuangValue;
          $sum_count_unknown += $unknownMuangValue;
          $sum_all_count_unknown += $unknownMuangValue;
        }else if($compare == true && $compareThey == true && $compareUnknown == false){
            $reMuangArray[$i] = array('name' => $allMuangArrayName,
                                    'count_all' => $allMaungArrayCount,
                                    'count_we' => $weMuangValue,
                                    'count_they' => $theyMuangValue,
                                    'count_unknown' => "0"
                              );
          $sum_count_all += $allMaungArrayCount;
          $sum_count_we += $weMuangValue;
          $sum_count_they += $theyMuangValue;
        }else if($compare == false && $compareThey == true && $compareUnknown == true){
            $reMuangArray[$i] = array('name' => $allMuangArrayName,
                                    'count_all' => $allMaungArrayCount,
                                    'count_we' => "0",
                                    'count_they' => $theyMuangValue,
                                    'count_unknown' => $unknownMuangValue
                              );
          $sum_count_all += $allMaungArrayCount;
          $sum_count_they += $theyMuangValue;
          $sum_count_unknown += $unknownValue;
          $sum_all_count_unknown += $unknownMuangValue;
        }else if($compare == true && $compareThey == false && $compareUnknown == false){
            $reMuangArray[$i] = array('name' => $allMuangArrayName,
                                    'count_all' => $allMaungArrayCount,
                                    'count_we' => $weMuangValue,
                                    'count_they' => "0",
                                    'count_unknown' => "0"
                              );
          $sum_count_all += $allMaungArrayCount;
          $sum_count_we += $weMuangValue;
        }else if($compare == false && $compareThey == true && $compareUnknown == false){
            $reMuangArray[$i] = array('name' => $allMuangArrayName,
                                    'count_all' => $allMaungArrayCount,
                                    'count_we' => "0",
                                    'count_they' => $theyMuangValue,
                                    'count_unknown' =>  "0"
                              );
          $sum_count_all += $allMaungArrayCount;
          $sum_count_they += $theyMuangValue;
        }else if($compare == false && $compareThey == false && $compareUnknown == true){
            $reMuangArray[$i] = array('name' => $allMuangArrayName,
                                    'count_all' => $allMaungArrayCount,
                                    'count_we' => "0",
                                    'count_they' => "0",
                                    'count_unknown' => $unknownMuangValue
                              );
          $sum_count_all += $allMaungArrayCount;
          $sum_count_none_canvasser += $unknownMuangValue;
          $sum_all_count_unknown += $unknownMuangValue;
        }
      }

      //var_dump($reMuangArray); exit;
    $render->assign('district_muang', "อ.เมือง");
    $render->assign('sum_count_all', $sum_count_all);
    $render->assign('sum_count_we', $sum_count_we);
    $render->assign('sum_count_they', $sum_count_they);
    $render->assign('sum_count_none_canvasser', $sum_count_none_canvasser);
    $render->assign('sum_all_count_unknown', $sum_all_count_unknown);
    $render->assign('sum_count_unknown', $sum_count_unknown);
    $render->assign('objectArray', $reMuangArray);


      //////////////////////////////////////////////////////////////////////
      //////////////////////////////////////////////////////////////////////
      //
      // Query khet2 all
      //
      //////////////////////////////////////////////////////////////////////
      //////////////////////////////////////////////////////////////////////
      //Get data from 5408 หนองม่วงไข่
      $query = "SELECT 	tam_name, COUNT(aco_id) AS count_nhongmuangkhai_all, tam_latitude, tam_longitude
                        FROM 
                          zikuladb.pn_degis_contact, zikuladb.`zk_votedatacenter_tambon` 
                        WHERE (aco_district_id =  5408 || aco_district_id =  5419)
                        AND tam_id = aco_tumbol_id
                        GROUP BY tam_name
                        ORDER BY tam_name";
      $column = array(
                "name", "count_nhongmuangkhai_all"
                );

      $result = DBUtil::executeSQL($query);
      $allNhongmuangkhaiArray = DBUtil::marshallObjects ($result, $column);

      //Get data from 5408 หนองม่วงไข่
      $query = "SELECT 	tam_name, COUNT(aco_id) AS count_nhongmuangkhai_we, tam_latitude, tam_longitude
                        FROM 
                          zikuladb.pn_degis_contact, zikuladb.`zk_votedatacenter_tambon` 
                        WHERE (aco_district_id =  5408 || aco_district_id =  5419)
                        AND tam_id = aco_tumbol_id
                        AND aco_remarkv =1 
                        GROUP BY tam_name
                        ORDER BY tam_name";
      $column = array(
                "name", "count_nhongmuangkhai_we"
                );

      $result = DBUtil::executeSQL($query);
      $weNhongmuangkhaiArray = DBUtil::marshallObjects ($result, $column);

      //Get data from 5408 หนองม่วงไข่
      $query = "SELECT 	tam_name, COUNT(aco_id) AS count_nhongmuangkhai_they, tam_latitude, tam_longitude
                        FROM 
                          zikuladb.pn_degis_contact, zikuladb.`zk_votedatacenter_tambon` 
                        WHERE (aco_district_id =  5408 || aco_district_id =  5419)
                        AND tam_id = aco_tumbol_id
                        AND aco_remarkv = 0
                        AND aco_remarkv2 =1
                        GROUP BY tam_name
                        ORDER BY tam_name";
      $column = array(
                "name", "count_nhongmuangkhai_they"
                );

      $result = DBUtil::executeSQL($query);
      $theyNhongmuangkhaiArray = DBUtil::marshallObjects ($result, $column);

      //Get data from 5408 หนองม่วงไข่
      $query = "SELECT 	tam_name, COUNT(aco_id) AS count_nhongmuangkhai_unknown, tam_latitude, tam_longitude
                        FROM 
                          zikuladb.pn_degis_contact, zikuladb.`zk_votedatacenter_tambon` 
                        WHERE (aco_district_id =  5408 || aco_district_id =  5419)
                        AND tam_id = aco_tumbol_id
                        AND aco_remarkv =0
                        AND aco_remarkv2 =0
                        GROUP BY tam_name
                        ORDER BY tam_name";
      $column = array(
                "name", "count_nhongmuangkhai_unknown"
                );

      $result = DBUtil::executeSQL($query);
      $unknownNhongmuangkhaiArray = DBUtil::marshallObjects ($result, $column);

      //Nhongmuangkhai merge array
      for($i=0; $i<count($allNhongmuangkhaiArray); $i++){
        $compare = false;
        $compareThey = false;
        $compareUnknown = false;
        $allNhongmuangkhaiArrayName = $allNhongmuangkhaiArray[$i]['name'];
        $allNhongmuangkhaiArrayCount = $allNhongmuangkhaiArray[$i]['count_nhongmuangkhai_all'];

        //Compare we
        for($j=0; $j<count($weNhongmuangkhaiArray); $j++){
          if($weNhongmuangkhaiArray[$j]['name'] == $allNhongmuangkhaiArrayName){
            //echo $weNhongmuangkhaiArray[$j]['aco_addr_moo']." with ".$allNhongmuangkhaiArray[$i]['aco_addr_moo']."<br>";
            $compare = true;
            $weNhongmuangkhaiValue = $weNhongmuangkhaiArray[$j]['count_nhongmuangkhai_we'];
          }
        }

        //Compare they
        for($k=0; $k<count($theyNhongmuangkhaiArray); $k++){
          if($theyNhongmuangkhaiArray[$k]['name'] == $allNhongmuangkhaiArrayName){
            //echo $theyNhongmuangkhaiArray[$k]['aco_addr_moo']." with ".$allNhongmuangkhaiArray[$i]['aco_addr_moo']."<br>";
            $compareThey = true;
            $theyNhongmuangkhaiValue = $theyNhongmuangkhaiArray[$k]['count_nhongmuangkhai_they'];
          }
        }

        //Compare unknow
        for($l=0; $l<count($unknownNhongmuangkhaiArray); $l++){
          if($unknownNhongmuangkhaiArray[$l]['name'] == $allNhongmuangkhaiArrayName){
            //echo $unknownNhongmuangkhaiArray[$l]['aco_addr_moo']." with ".$allNhongmuangkhaiArray[$i]['aco_addr_moo']."<br>";
            $compareUnknown = true;
            $unknownNhongmuangkhaiValue = $unknownNhongmuangkhaiArray[$l]['count_nhongmuangkhai_unknown'];
          }
        }

        if($compare == true && $compareThey == true && $compareUnknown == true){
            $reNhongmuangkhaiArray[$i] = array('name' => $allNhongmuangkhaiArrayName,
                                    'count_nhongmuangkhai_all' => $allNhongmuangkhaiArrayCount,
                                    'count_nhongmuangkhai_we' => $weNhongmuangkhaiValue,
                                    'count_nhongmuangkhai_they' => $theyNhongmuangkhaiValue,
                                    'count_nhongmuangkhai_unknown' => $unknownNhongmuangkhaiValue
                              );
          $sum_count_nhongmuangkhai_all += $allNhongmuangkhaiArrayCount;
          $sum_count_nhongmuangkhai_we += $weNhongmuangkhaiValue;
          $sum_count_nhongmuangkhai_they += $theyNhongmuangkhaiValue;
          $sum_count_nhongmuangkhai_unknown += $unknownNhongmuangkhaiValue;
          $sum_all_count_nhongmuangkhai_unknown += $unknownNhongmuangkhaiValue;
        }else if($compare == false && $compareThey == true && $compareUnknown == true){
            $reNhongmuangkhaiArray[$i] = array('name' => $allNhongmuangkhaiArrayName,
                                    'count_nhongmuangkhai_all' => $allNhongmuangkhaiArrayCount,
                                    'count_nhongmuangkhai_we' => "0",
                                    'count_nhongmuangkhai_they' => $theyNhongmuangkhaiValue,
                                    'count_nhongmuangkhai_unknown' => $unknownNhongmuangkhaiValue
                              );
          $sum_count_nhongmuangkhai_all += $allNhongmuangkhaiArrayCount;
          $sum_count_nhongmuangkhai_they += $theyNhongmuangkhaiValue;
          $sum_count_nhongmuangkhai_unknown += $unknownNhongmuangkhaiValue;
          $sum_all_count_nhongmuangkhai_unknown += $unknownNhongmuangkhaiValue;
        }else if($compare == true && $compareThey == false && $compareUnknown == true){
            $reNhongmuangkhaiArray[$i] = array('name' => $allNhongmuangkhaiArrayName,
                                    'count_nhongmuangkhai_all' => $allNhongmuangkhaiArrayCount,
                                    'count_nhongmuangkhai_we' => $weNhongmuangkhaiValue,
                                    'count_nhongmuangkhai_they' => "0",
                                    'count_nhongmuangkhai_unknown' => $unknownNhongmuangkhaiValue
                              );
          $sum_count_nhongmuangkhai_all += $allNhongmuangkhaiArrayCount;
          $sum_count_nhongmuangkhai_we += $weNhongmuangkhaiValue;
          $sum_count_nhongmuangkhai_unknown += $unknownNhongmuangkhaiValue;
          $sum_all_count_nhongmuangkhai_unknown += $unknownNhongmuangkhaiValue;
        }else if($compare == true && $compareThey == true && $compareUnknown == false){
            $reNhongmuangkhaiArray[$i] = array('name' => $allNhongmuangkhaiArrayName,
                                    'count_nhongmuangkhai_all' => $allNhongmuangkhaiArrayCount,
                                    'count_nhongmuangkhai_we' => $weNhongmuangkhaiValue,
                                    'count_nhongmuangkhai_they' => $theyNhongmuangkhaiValue,
                                    'count_nhongmuangkhai_unknown' => "0"
                              );
          $sum_count_nhongmuangkhai_all += $allNhongmuangkhaiArrayCount;
          $sum_count_nhongmuangkhai_we += $weNhongmuangkhaiValue;
          $sum_count_nhongmuangkhai_they += $theyNhongmuangkhaiValue;
        }else if($compare == false && $compareThey == true && $compareUnknown == true){
            $reNhongmuangkhaiArray[$i] = array('name' => $allNhongmuangkhaiArrayName,
                                    'count_nhongmuangkhai_all' => $allNhongmuangkhaiArrayCount,
                                    'count_nhongmuangkhai_we' => "0",
                                    'count_nhongmuangkhai_they' => $theyNhongmuangkhaiValue,
                                    'count_nhongmuangkhai_unknown' => $unknownNhongmuangkhaiValue
                              );
          $sum_count_nhongmuangkhai_all += $allNhongmuangkhaiArrayCount;
          $sum_count_nhongmuangkhai_they += $theyNhongmuangkhaiValue;
          $sum_count_nhongmuangkhai_unknown += $unknownNhongmuangkhaiValue;
          $sum_all_count_nhongmuangkhai_unknown += $unknownNhongmuangkhaiValue;
        }else if($compare == true && $compareThey == false && $compareUnknown == false){
            $reNhongmuangkhaiArray[$i] = array('name' => $allNhongmuangkhaiArrayName,
                                    'count_nhongmuangkhai_all' => $allNhongmuangkhaiArrayCount,
                                    'count_nhongmuangkhai_we' => $weNhongmuangkhaiValue,
                                    'count_nhongmuangkhai_they' => "0",
                                    'count_nhongmuangkhai_unknown' => "0"
                              );
          $sum_count_nhongmuangkhai_all += $allNhongmuangkhaiArrayCount;
          $sum_count_nhongmuangkhai_we += $weNhongmuangkhaiValue;
        }else if($compare == false && $compareThey == true && $compareUnknown == false){
            $reNhongmuangkhaiArray[$i] = array('name' => $allNhongmuangkhaiArrayName,
                                    'count_nhongmuangkhai_all' => $allNhongmuangkhaiArrayCount,
                                    'count_nhongmuangkhai_we' => "0",
                                    'count_nhongmuangkhai_they' => $theyNhongmuangkhaiValue,
                                    'count_nhongmuangkhai_unknown' =>  "0"
                              );
          $sum_count_nhongmuangkhai_all += $allNhongmuangkhaiArrayCount;
          $sum_count_nhongmuangkhai_they += $theyNhongmuangkhaiValue;
        }else if($compare == false && $compareThey == false && $compareUnknown == true){
            $reNhongmuangkhaiArray[$i] = array('name' => $allNhongmuangkhaiArrayName,
                                    'count_nhongmuangkhai_all' => $allNhongmuangkhaiArrayCount,
                                    'count_nhongmuangkhai_we' => "0",
                                    'count_nhongmuangkhai_they' => "0",
                                    'count_nhongmuangkhai_unknown' => $unknownNhongmuangkhaiValue
                              );
          $sum_count_nhongmuangkhai_all += $allNhongmuangkhaiArrayCount;
          $sum_count_nhongmuangkhai_none_canvasser += $unknownNhongmuangkhaiValue;
          $sum_all_count_nhongmuangkhai_unknown += $unknownNhongmuangkhaiValue;
        }
      }

    //var_dump($reNhongmuangkhaiArray['count_nhongmuangkhai_all']); exit;
    $render->assign('reportNMK', "nmk");
    $render->assign('district_nhongmuangkhai', "อ.หนองม่วงไข่");
    $render->assign('sum_count_nhongmuangkhai_all', $sum_count_nhongmuangkhai_all);
    $render->assign('sum_count_nhongmuangkhai_we', $sum_count_nhongmuangkhai_we);
    $render->assign('sum_count_nhongmuangkhai_they', $sum_count_nhongmuangkhai_they);
    $render->assign('sum_count_nhongmuangkhai_none_canvasser', $sum_count_nhongmuangkhai_none_canvasser);
    $render->assign('sum_all_count_nhongmuangkhai_unknown', $sum_all_count_nhongmuangkhai_unknown);
    $render->assign('sum_count_nhongmuangkhai_unknown', $sum_count_nhongmuangkhai_unknown);
    $render->assign('objectNhongmuangkhaiArray', $reNhongmuangkhaiArray);








      //////////////////////////////////////////////////////////////////////
      //////////////////////////////////////////////////////////////////////
      //
      // Query khet2 all
      //
      //////////////////////////////////////////////////////////////////////
      //////////////////////////////////////////////////////////////////////
      //Get data from 5406 สอง
      $query = "SELECT 	tam_name, COUNT(aco_id) AS count_song_all, tam_latitude, tam_longitude
                        FROM 
                          zikuladb.pn_degis_contact, zikuladb.`zk_votedatacenter_tambon` 
                        WHERE (aco_district_id =  5406 || aco_district_id =  5417)
                        AND tam_id = aco_tumbol_id
                        GROUP BY tam_name
                        ORDER BY tam_name";
      $column = array(
                "name", "count_song_all"
                );

      $result = DBUtil::executeSQL($query);
      $allSongArray = DBUtil::marshallObjects ($result, $column);




      //Get data from 5406 สอง
      $query = "SELECT 	tam_name, COUNT(aco_id) AS count_song_we, tam_latitude, tam_longitude
                        FROM 
                          zikuladb.pn_degis_contact, zikuladb.`zk_votedatacenter_tambon` 
                        WHERE (aco_district_id =  5406 || aco_district_id =  5417)
                        AND tam_id = aco_tumbol_id
                        AND aco_remarkv =1
                        GROUP BY tam_name
                        ORDER BY tam_name";
      $column = array(
                "name", "count_song_we"
                );

      $result = DBUtil::executeSQL($query);
      $weSongArray = DBUtil::marshallObjects ($result, $column);




      //Get data from 5406 สอง
      $query = "SELECT 	tam_name, COUNT(aco_id) AS count_song_they, tam_latitude, tam_longitude
                        FROM 
                          zikuladb.pn_degis_contact, zikuladb.`zk_votedatacenter_tambon` 
                        WHERE (aco_district_id =  5406 || aco_district_id =  5417)
                        AND tam_id = aco_tumbol_id
                        AND aco_remarkv = 0
                        AND aco_remarkv2 =1
                        GROUP BY tam_name
                        ORDER BY tam_name";
      $column = array(
                "name", "count_song_they"
                );

      $result = DBUtil::executeSQL($query);
      $theySongArray = DBUtil::marshallObjects ($result, $column);




      //Get data from 5406 สอง
      $query = "SELECT 	tam_name, COUNT(aco_id) AS count_song_unknown, tam_latitude, tam_longitude
                        FROM 
                          zikuladb.pn_degis_contact, zikuladb.`zk_votedatacenter_tambon` 
                        WHERE (aco_district_id =  5406 || aco_district_id =  5417)
                        AND tam_id = aco_tumbol_id
                        AND aco_remarkv =0
                        AND aco_remarkv2 =0
                        GROUP BY tam_name
                        ORDER BY tam_name";
      $column = array(
                "name", "count_song_unknown"
                );

      $result = DBUtil::executeSQL($query);
      $unknownSongArray = DBUtil::marshallObjects ($result, $column);


      //Song merge array
      for($i=0; $i<count($allSongArray); $i++){
        $compare = false;
        $compareThey = false;
        $compareUnknown = false;
        $allSongArrayName = $allSongArray[$i]['name'];
        $allSongArrayCount = $allSongArray[$i]['count_song_all'];

        //Compare we
        for($j=0; $j<count($weSongArray); $j++){
          if($weSongArray[$j]['name'] == $allSongArrayName){
            //echo $weSongArray[$j]['aco_addr_moo']." with ".$allSongArray[$i]['aco_addr_moo']."<br>";
            $compare = true;
            $weSongValue = $weSongArray[$j]['count_song_we'];
          }
        }

        //Compare they
        for($k=0; $k<count($theySongArray); $k++){
          if($theySongArray[$k]['name'] == $allSongArrayName){
            //echo $theySongArray[$k]['aco_addr_moo']." with ".$allSongArray[$i]['aco_addr_moo']."<br>";
            $compareThey = true;
            $theySongValue = $theySongArray[$k]['count_song_they'];
          }
        }

        //Compare unknow
        for($l=0; $l<count($unknownSongArray); $l++){
          if($unknownSongArray[$l]['name'] == $allSongArrayName){
            //echo $unknownSongArray[$l]['aco_addr_moo']." with ".$allSongArray[$i]['aco_addr_moo']."<br>";
            $compareUnknown = true;
            $unknownSongValue = $unknownSongArray[$l]['count_song_unknown'];
          }
        }

        if($compare == true && $compareThey == true && $compareUnknown == true){
            $reSongArray[$i] = array('name' => $allSongArrayName,
                                    'count_song_all' => $allSongArrayCount,
                                    'count_song_we' => $weSongValue,
                                    'count_song_they' => $theySongValue,
                                    'count_song_unknown' => $unknownSongValue
                              );
          $sum_count_song_all += $allSongArrayCount;
          $sum_count_song_we += $weSongValue;
          $sum_count_song_they += $theySongValue;
          $sum_count_song_unknown += $unknownSongValue;
          $sum_all_count_song_unknown += $unknownSongValue;
        }else if($compare == false && $compareThey == true && $compareUnknown == true){
            $reSongArray[$i] = array('name' => $allSongArrayName,
                                    'count_song_all' => $allSongArrayCount,
                                    'count_song_we' => "0",
                                    'count_song_they' => $theySongValue,
                                    'count_song_unknown' => $unknownSongValue
                              );
          $sum_count_song_all += $allSongArrayCount;
          $sum_count_song_they += $theySongValue;
          $sum_count_song_unknown += $unknownSongValue;
          $sum_all_count_song_unknown += $unknownSongValue;
        }else if($compare == true && $compareThey == false && $compareUnknown == true){
            $reSongArray[$i] = array('name' => $allSongArrayName,
                                    'count_song_all' => $allSongArrayCount,
                                    'count_song_we' => $weSongValue,
                                    'count_song_they' => "0",
                                    'count_song_unknown' => $unknownSongValue
                              );
          $sum_count_song_all += $allSongArrayCount;
          $sum_count_song_we += $weSongValue;
          $sum_count_song_unknown += $unknownSongValue;
          $sum_all_count_song_unknown += $unknownSongValue;
        }else if($compare == true && $compareThey == true && $compareUnknown == false){
            $reSongArray[$i] = array('name' => $allSongArrayName,
                                    'count_song_all' => $allSongArrayCount,
                                    'count_song_we' => $weSongValue,
                                    'count_song_they' => $theySongValue,
                                    'count_song_unknown' => "0"
                              );
          $sum_count_song_all += $allSongArrayCount;
          $sum_count_song_we += $weSongValue;
          $sum_count_song_they += $theySongValue;
        }else if($compare == false && $compareThey == true && $compareUnknown == true){
            $reSongArray[$i] = array('name' => $allSongArrayName,
                                    'count_song_all' => $allSongArrayCount,
                                    'count_song_we' => "0",
                                    'count_song_they' => $theySongValue,
                                    'count_song_unknown' => $unknownSongValue
                              );
          $sum_count_song_all += $allSongArrayCount;
          $sum_count_song_they += $theySongValue;
          $sum_count_song_unknown += $unknownSongValue;
          $sum_all_count_song_unknown += $unknownSongValue;
        }else if($compare == true && $compareThey == false && $compareUnknown == false){
            $reSongArray[$i] = array('name' => $allSongArrayName,
                                    'count_song_all' => $allSongArrayCount,
                                    'count_song_we' => $weSongValue,
                                    'count_song_they' => "0",
                                    'count_song_unknown' => "0"
                              );
          $sum_count_song_all += $allSongArrayCount;
          $sum_count_song_we += $weSongValue;
        }else if($compare == false && $compareThey == true && $compareUnknown == false){
            $reSongArray[$i] = array('name' => $allSongArrayName,
                                    'count_song_all' => $allSongArrayCount,
                                    'count_song_we' => "0",
                                    'count_song_they' => $theySongValue,
                                    'count_song_unknown' =>  "0"
                              );
          $sum_count_song_all += $allSongArrayCount;
          $sum_count_song_they += $theySongValue;
        }else if($compare == false && $compareThey == false && $compareUnknown == true){
            $reSongArray[$i] = array('name' => $allSongArrayName,
                                    'count_song_all' => $allSongArrayCount,
                                    'count_song_we' => "0",
                                    'count_song_they' => "0",
                                    'count_song_unknown' => $unknownSongValue
                              );
          $sum_count_song_all += $allSongArrayCount;
          $sum_count_song_none_canvasser += $unknownSongValue;
          $sum_all_count_song_unknown += $unknownSongValue;
        }
      }

    //var_dump($reSongArray['count_song_all']); exit;
    $render->assign('reportSong', "song");
    $render->assign('district_song', "อ.สอง");
    $render->assign('sum_count_song_all', $sum_count_song_all);
    $render->assign('sum_count_song_we', $sum_count_song_we);
    $render->assign('sum_count_song_they', $sum_count_song_they);
    $render->assign('sum_count_song_none_canvasser', $sum_count_song_none_canvasser);
    $render->assign('sum_all_count_song_unknown', $sum_all_count_song_unknown);
    $render->assign('sum_count_song_unknown', $sum_count_song_unknown);
    $render->assign('objectSongArray', $reSongArray);










      //////////////////////////////////////////////////////////////////////
      //////////////////////////////////////////////////////////////////////
      //
      // Query khet2 rongkwang
      //
      //////////////////////////////////////////////////////////////////////
      //////////////////////////////////////////////////////////////////////
      //Get data from 5406 ร้องกวาง
      $query = "SELECT 	tam_name, COUNT(aco_id) AS count_rongkwang_all, tam_latitude, tam_longitude
                        FROM 
                          zikuladb.pn_degis_contact, zikuladb.`zk_votedatacenter_tambon` 
                        WHERE (aco_district_id =  5415 || aco_district_id =  5402)
                        AND tam_id = aco_tumbol_id
                        GROUP BY tam_name
                        ORDER BY tam_name";
      $column = array(
                "name", "count_rongkwang_all", "latitude", "longitude"
                );

      $result = DBUtil::executeSQL($query);
      $allRongkwangArray = DBUtil::marshallObjects ($result, $column);




      //Get data from 5406 ร้องกวาง
      $query = "SELECT 	tam_name, COUNT(aco_id) AS count_rongkwang_we, tam_latitude, tam_longitude
                        FROM 
                          zikuladb.pn_degis_contact, zikuladb.`zk_votedatacenter_tambon` 
                        WHERE (aco_district_id =  5415 || aco_district_id =  5402)
                        AND tam_id = aco_tumbol_id
                        AND aco_remarkv =1
                        GROUP BY tam_name
                        ORDER BY tam_name";
      $column = array(
                "name", "count_rongkwang_we", "latitude", "longitude"
                );

      $result = DBUtil::executeSQL($query);
      $weRongkwangArray = DBUtil::marshallObjects ($result, $column);




      //Get data from 5406 ร้องกวาง
      $query = "SELECT 	tam_name, COUNT(aco_id) AS count_rongkwang_they, tam_latitude, tam_longitude
                        FROM 
                          zikuladb.pn_degis_contact, zikuladb.`zk_votedatacenter_tambon` 
                        WHERE (aco_district_id =  5415 || aco_district_id =  5402)
                        AND tam_id = aco_tumbol_id
                        AND aco_remarkv = 0
                        AND aco_remarkv2 =1
                        GROUP BY tam_name
                        ORDER BY tam_name";
      $column = array(
                "name", "count_rongkwang_they", "latitude", "longitude"
                );

      $result = DBUtil::executeSQL($query);
      $theyRongkwangArray = DBUtil::marshallObjects ($result, $column);




      //Get data from 5406 ร้องกวาง
      $query = "SELECT 	tam_name, COUNT(aco_id) AS count_rongkwang_unknown, tam_latitude, tam_longitude
                        FROM 
                          zikuladb.pn_degis_contact, zikuladb.`zk_votedatacenter_tambon` 
                        WHERE (aco_district_id =  5415 || aco_district_id =  5402)
                        AND tam_id = aco_tumbol_id
                        AND aco_remarkv =0
                        AND aco_remarkv2 =0
                        GROUP BY tam_name
                        ORDER BY tam_name";
      $column = array(
                "name", "count_rongkwang_unknown", "latitude", "longitude"
                );

      $result = DBUtil::executeSQL($query);
      $unknownRongkwangArray = DBUtil::marshallObjects ($result, $column);


      //Rongkwang merge array
      for($i=0; $i<count($allRongkwangArray); $i++){
        $compare = false;
        $compareThey = false;
        $compareUnknown = false;
        $allRongkwangArrayName = $allRongkwangArray[$i]['name'];
        $allRongkwangArrayCount = $allRongkwangArray[$i]['count_rongkwang_all'];

        //Compare we
        for($j=0; $j<count($weRongkwangArray); $j++){
          if($weRongkwangArray[$j]['name'] == $allRongkwangArrayName){
            //echo $weRongkwangArray[$j]['aco_addr_moo']." with ".$allRongkwangArray[$i]['aco_addr_moo']."<br>";
            $compare = true;
            $weRongkwangValue = $weRongkwangArray[$j]['count_rongkwang_we'];
          }
        }

        //Compare they
        for($k=0; $k<count($theyRongkwangArray); $k++){
          if($theyRongkwangArray[$k]['name'] == $allRongkwangArrayName){
            //echo $theyRongkwangArray[$k]['aco_addr_moo']." with ".$allRongkwangArray[$i]['aco_addr_moo']."<br>";
            $compareThey = true;
            $theyRongkwangValue = $theyRongkwangArray[$k]['count_rongkwang_they'];
          }
        }

        //Compare unknow
        for($l=0; $l<count($unknownRongkwangArray); $l++){
          if($unknownRongkwangArray[$l]['name'] == $allRongkwangArrayName){
            //echo $unknownRongkwangArray[$l]['aco_addr_moo']." with ".$allRongkwangArray[$i]['aco_addr_moo']."<br>";
            $compareUnknown = true;
            $unknownRongkwangValue = $unknownRongkwangArray[$l]['count_rongkwang_unknown'];
          }
        }

        if($compare == true && $compareThey == true && $compareUnknown == true){
            $reRongkwangArray[$i] = array('name' => $allRongkwangArrayName,
                                    'count_rongkwang_all' => $allRongkwangArrayCount,
                                    'count_rongkwang_we' => $weRongkwangValue,
                                    'count_rongkwang_they' => $theyRongkwangValue,
                                    'count_rongkwang_unknown' => $unknownRongkwangValue
                              );
          $sum_count_rongkwang_all += $allRongkwangArrayCount;
          $sum_count_rongkwang_we += $weRongkwangValue;
          $sum_count_rongkwang_they += $theyRongkwangValue;
          $sum_count_rongkwang_unknown += $unknownRongkwangValue;
          $sum_all_count_rongkwang_unknown += $unknownRongkwangValue;
        }else if($compare == false && $compareThey == true && $compareUnknown == true){
            $reRongkwangArray[$i] = array('name' => $allRongkwangArrayName,
                                    'count_rongkwang_all' => $allRongkwangArrayCount,
                                    'count_rongkwang_we' => "0",
                                    'count_rongkwang_they' => $theyRongkwangValue,
                                    'count_rongkwang_unknown' => $unknownRongkwangValue
                              );
          $sum_count_rongkwang_all += $allRongkwangArrayCount;
          $sum_count_rongkwang_they += $theyRongkwangValue;
          $sum_count_rongkwang_unknown += $unknownRongkwangValue;
          $sum_all_count_rongkwang_unknown += $unknownRongkwangValue;
        }else if($compare == true && $compareThey == false && $compareUnknown == true){
            $reRongkwangArray[$i] = array('name' => $allRongkwangArrayName,
                                    'count_rongkwang_all' => $allRongkwangArrayCount,
                                    'count_rongkwang_we' => $weRongkwangValue,
                                    'count_rongkwang_they' => "0",
                                    'count_rongkwang_unknown' => $unknownRongkwangValue
                              );
          $sum_count_rongkwang_all += $allRongkwangArrayCount;
          $sum_count_rongkwang_we += $weRongkwangValue;
          $sum_count_rongkwang_unknown += $unknownRongkwangValue;
          $sum_all_count_rongkwang_unknown += $unknownRongkwangValue;
        }else if($compare == true && $compareThey == true && $compareUnknown == false){
            $reRongkwangArray[$i] = array('name' => $allRongkwangArrayName,
                                    'count_rongkwang_all' => $allRongkwangArrayCount,
                                    'count_rongkwang_we' => $weRongkwangValue,
                                    'count_rongkwang_they' => $theyRongkwangValue,
                                    'count_rongkwang_unknown' => "0"
                              );
          $sum_count_rongkwang_all += $allRongkwangArrayCount;
          $sum_count_rongkwang_we += $weRongkwangValue;
          $sum_count_rongkwang_they += $theyRongkwangValue;
        }else if($compare == false && $compareThey == true && $compareUnknown == true){
            $reRongkwangArray[$i] = array('name' => $allRongkwangArrayName,
                                    'count_rongkwang_all' => $allRongkwangArrayCount,
                                    'count_rongkwang_we' => "0",
                                    'count_rongkwang_they' => $theyRongkwangValue,
                                    'count_rongkwang_unknown' => $unknownRongkwangValue
                              );
          $sum_count_rongkwang_all += $allRongkwangArrayCount;
          $sum_count_rongkwang_they += $theyRongkwangValue;
          $sum_count_rongkwang_unknown += $unknownRongkwangValue;
          $sum_all_count_rongkwang_unknown += $unknownRongkwangValue;
        }else if($compare == true && $compareThey == false && $compareUnknown == false){
            $reRongkwangArray[$i] = array('name' => $allRongkwangArrayName,
                                    'count_rongkwang_all' => $allRongkwangArrayCount,
                                    'count_rongkwang_we' => $weRongkwangValue,
                                    'count_rongkwang_they' => "0",
                                    'count_rongkwang_unknown' => "0"
                              );
          $sum_count_rongkwang_all += $allRongkwangArrayCount;
          $sum_count_rongkwang_we += $weRongkwangValue;
        }else if($compare == false && $compareThey == true && $compareUnknown == false){
            $reRongkwangArray[$i] = array('name' => $allRongkwangArrayName,
                                    'count_rongkwang_all' => $allRongkwangArrayCount,
                                    'count_rongkwang_we' => "0",
                                    'count_rongkwang_they' => $theyRongkwangValue,
                                    'count_rongkwang_unknown' =>  "0"
                              );
          $sum_count_rongkwang_all += $allRongkwangArrayCount;
          $sum_count_rongkwang_they += $theyRongkwangValue;
        }else if($compare == false && $compareThey == false && $compareUnknown == true){
            $reRongkwangArray[$i] = array('name' => $allRongkwangArrayName,
                                    'count_rongkwang_all' => $allRongkwangArrayCount,
                                    'count_rongkwang_we' => "0",
                                    'count_rongkwang_they' => "0",
                                    'count_rongkwang_unknown' => $unknownRongkwangValue
                              );
          $sum_count_rongkwang_all += $allRongkwangArrayCount;
          $sum_count_rongkwang_none_canvasser += $unknownRongkwangValue;
          $sum_all_count_rongkwang_unknown += $unknownRongkwangValue;
        }
      }

      //var_dump($reRongkwangArray['count_rongkwang_all']); exit;
      $render->assign('reportRongkwang', "rongkwang");
      $render->assign('district_rongkwang', "อ.ร้องกวาง");
      $render->assign('sum_count_rongkwang_all', $sum_count_rongkwang_all);
      $render->assign('sum_count_rongkwang_we', $sum_count_rongkwang_we);
      $render->assign('sum_count_rongkwang_they', $sum_count_rongkwang_they);
      $render->assign('sum_count_rongkwang_none_canvasser', $sum_count_rongkwang_none_canvasser);
      $render->assign('sum_all_count_rongkwang_unknown', $sum_all_count_rongkwang_unknown);
      $render->assign('sum_count_rongkwang_unknown', $sum_count_rongkwang_unknown);
      $render->assign('objectRongkwangArray', $reRongkwangArray);


      $render->assign('total_sum_we', $sum_count_muang_we+$sum_count_nhongmuangkhai_we+$sum_count_song_we+$sum_count_rongkwang_we);
      $render->assign('total_sum_they', $sum_count_muang_they+$sum_count_nhongmuangkhai_they+$sum_count_song_they+$sum_count_rongkwang_they);
      $render->assign('total_sum_unknown', 
                      $sum_count_muang_unknown+$sum_count_nhongmuangkhai_unknown+$sum_count_song_unknown+$sum_count_rongkwang_unknown);

    }else if($form[khet_id] == 3 && $form['pro_id'] == 54){

    }

    //pnShutdown();
  }

  return $render->fetch('admin_remark_report.htm');
}

  function VoteDataCenter_remark_person(){
    $moo = FormUtil::getPassedValue ('moo', null, 'REQUEST');
    $select = FormUtil::getPassedValue ('select', null, 'REQUEST');
    $tam_id = FormUtil::getPassedValue ('tam_id', null, 'REQUEST');
    $render = pnRender::getInstance('VoteDataCenter');
    if($moo && $select ){

      if($select == "we"){
        $query = "
                  SELECT 	`aco_id`,
                    `aco_province_id`, 
                    `aco_district_id`, 
                    `aco_tumbol_id`, 
                    `aco_person_id`, 
                    `aco_prefix_name`, 
                    `aco_first_name`, 
                    `aco_last_name`, 
                    `aco_addr_house_no`, 
                    IF(INSTR(aco_addr_house_no, '/')=0,0,SUBSTRING_INDEX( aco_addr_house_no , '/', -1 )) AS aco_sub_addr_house_no,
                    `aco_addr_moo`, 
                    `aco_addr_trok`, 
                    `aco_addr_soi`, 
                    `aco_addr_road`
                  FROM 
                    `zikuladb`.`pn_degis_contact` 
                  WHERE aco_addr_moo = ".$moo." 
                    AND aco_tumbol_id = ".$tam_id." 
                    AND aco_remarkv = 1    
                  ORDER BY CAST(aco_addr_house_no AS SIGNED INTEGER), aco_sub_addr_house_no, aco_id,aco_last_name 
                ";
      }else if($select == "they"){
        $query = "
                  SELECT 	`aco_id`,
                    `aco_province_id`, 
                    `aco_district_id`, 
                    `aco_tumbol_id`, 
                    `aco_person_id`, 
                    `aco_prefix_name`, 
                    `aco_first_name`, 
                    `aco_last_name`, 
                    `aco_addr_house_no`, 
                    IF(INSTR(aco_addr_house_no, '/')=0,0,SUBSTRING_INDEX( aco_addr_house_no , '/', -1 )) AS aco_sub_addr_house_no,
                    `aco_addr_moo`, 
                    `aco_addr_trok`, 
                    `aco_addr_soi`, 
                    `aco_addr_road`
                  FROM 
                    `zikuladb`.`pn_degis_contact` 
                  WHERE aco_addr_moo = ".$moo." 
                    AND aco_tumbol_id = ".$tam_id." 
                  AND aco_remarkv2 = 1    
                  ORDER BY CAST(aco_addr_house_no AS SIGNED INTEGER), aco_sub_addr_house_no, aco_last_name ";
      }else if($select == "unknown"){
        $query = "
                  SELECT 	`aco_id`,
                    `aco_province_id`, 
                    `aco_district_id`, 
                    `aco_tumbol_id`, 
                    `aco_person_id`, 
                    `aco_prefix_name`, 
                    `aco_first_name`, 
                    `aco_last_name`, 
                    `aco_addr_house_no`, 
                    IF(INSTR(aco_addr_house_no, '/')=0,0,SUBSTRING_INDEX( aco_addr_house_no , '/', -1 )) AS aco_sub_addr_house_no,
                    `aco_addr_moo`, 
                    `aco_addr_trok`, 
                    `aco_addr_soi`, 
                    `aco_addr_road`
                  FROM 
                    `zikuladb`.`pn_degis_contact` 
                  WHERE aco_addr_moo = ".$moo." 
                    AND aco_tumbol_id = ".$tam_id." 
                  AND aco_remarkv = 0    
                  AND aco_remarkv2 = 0    
                  ORDER BY CAST(aco_addr_house_no AS SIGNED INTEGER), aco_sub_addr_house_no, aco_last_name ";

      }

    $column = array(
                "aco_id",
                "aco_province_id", 
                "aco_district_id", 
                "aco_tumbol_id", 
                "aco_person_id", 
                "aco_prefix_name", 
                "aco_first_name", 
                "aco_last_name", 
                "aco_addr_house_no", 
                "aco_sub_addr_house_no",
                "aco_addr_moo", 
                "aco_addr_trok", 
                "aco_addr_soi", 
                "aco_addr_road"
              );

      $result = DBUtil::executeSQL($query);
      $objectArray = DBUtil::marshallObjects ($result, $column);
      //var_dump($objectArray[0]['aco_first_name']); exit;
      $render = pnRender::getInstance('VoteDataCenter');
      $render->assign('objectArray', $objectArray);

      return $render->fetch('admin_remark_person.htm');

    }else{
      return $render->fetch('admin_remark_report.htm');
    }
  }
?>